Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

180
Views
Angular cómo ajustar el valor de entrada con llaves dobles

Lo que quiero lograr es que cuando escriba dentro del campo de entrada "Foo" se convierta en {{Foo}}

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Primero crea esta directiva:

 @Directive({ selector: '[format-input]', }) export class FormatDirective implements DoCheck { valueIsNull:boolean = true; constructor(public _elementRef: ElementRef<HTMLInputElement>, private _renderer: Renderer2) { } ngDoCheck(): void { setTimeout(() => { if(this.valueIsNull){ this.format(); } }, 150) fromEvent(this._elementRef.nativeElement, 'blur') .pipe( debounceTime(150), distinctUntilChanged(), tap(() => { this.format(); }) ) .subscribe(); } format(){ this._elementRef.nativeElement.value = "{{ " + this._elementRef.nativeElement.value + " }}" this.valueIsNull = false; } }

Luego impórtelo a su módulo: por ejemplo, app.module:

 @NgModule({ declarations: [ FormatDirective ], imports: [CommonModule], exports: [ FormatDirective ] }) export class AppModule { }

Entonces puedes usarlo donde quieras:

 <input type="text" format-input />
about 4 years ago · Juan Pablo Isaza Report

0

Debe usar plantillas angulares para lograr esta Documentación oficial para plantillas e interpolación, y a continuación se proporciona un ejemplo de código. esto le ayudará a lograr su caso de uso.

https://angular.io/guide/interpolation https://angular.io/api/forms/NgModel

 import {Component} from '@angular/core'; import {NgForm} from '@angular/forms'; @Component({ selector: 'example-app', template: ` <form #f="ngForm" (ngSubmit)="onSubmit(f)" novalidate> <input name="first" ngModel required #first="ngModel"> <input name="last" ngModel> <button>Submit</button> </form> <p>First name value: {{ first.value }}</p> <p>First name valid: {{ first.valid }}</p> <p>Form value: {{ f.value | json }}</p> <p>Form valid: {{ f.valid }}</p> `, }) export class SimpleFormComp { onSubmit(f: NgForm) { console.log(f.value); // { first: '', last: '' } console.log(f.valid); // false } }

Gracias

Equipo Rigin

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!