Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

153
Vistas
angular2 and formControlName value in template

Oh angular2...why so hard?

<input type="text" formControlName="exposure" type="hidden">
<label>{{exposure}}</label>

If I use the formControlName in the input the value is correct.

How do I get the value of exposure in template? Its blank in the label

over 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

The formControlName directive is designed to be used with a parent FormGroupDirective (selector: [formGroup]).

It accepts the string name of the FormControl instance you want to link, and will look for a FormControl registered with that name in the closest FormGroup or FormArray above it.

Use form.get('exposure').value to get the control value.

Example:

<form [formGroup]="form">
    <input type="text" formControlName="exposure" type="hidden">
    <label>{{ form.get('exposure').value }}</label>
</form>

Alternatively

In your component class, define a getter property representing your form control:

export class MyComponent {
  form = new FormGroup({
    exposure: new FormControl('')
  });

  get exposure(): FormControl { return this.form.get('exposure'); }

Then, in your component template, you can reference exposure:

<input type="text" formControlName="exposure" type="hidden">
<label>{{exposure.value}}</label>
over 4 years ago · Santiago Trujillo Denunciar

0

Declare a template variable:

<input type="text" formControlName="exposure" type="hidden" #exposure>
<label>{{ exposure.value }}</label>
over 4 years ago · Santiago Trujillo Denunciar

0

If you are looking to print the current field values of a form in your template for testing purpose.

Use

<p>{{myForm.value|json}}</p>

enter image description here

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda