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
The
formControlName
directive is designed to be used with a parentFormGroupDirective
(selector:[formGroup]
).It accepts the string name of the
FormControl
instance you want to link, and will look for aFormControl
registered with that name in the closestFormGroup
orFormArray
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>
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>