Reputation: 1912
I'm building a data-driven form in Ionic 2, with a few fields. I'm trying to manually update the value of one control, when the value of the form changes. However, I'm getting this error: TypeError: _this.myForm.controls.name.setValue is not a function
. I have tried both with and without the <FormControl>
type cast, but the error remains.
import { Component } from '@angular/core';
import { FormBuilder, FormControl, FormGroup, Validators, REACTIVE_FORM_DIRECTIVES } from '@angular/forms';
@Component({
templateUrl: 'build/pages/lead-provider/add-bp/add-bp.html',
directives: [REACTIVE_FORM_DIRECTIVES]
})
export class AddBpPage {
private myForm: FormGroup;
constructor(private formBuilder: FormBuilder) {
this.myForm= formBuilder.group({
'name': ['', [Validators.required]],
'email': ['', [Validators.required]],
'phone': ['', [Validators.required]]
});
this.myForm.valueChanges.subscribe((value) => {
(<FormControl>this.myForm.controls['name']).setValue('abc');
});
}
}
Upvotes: 1
Views: 8820
Reputation: 657546
setValue
was added 2 weeks ago. Therefore RC.4 can't contain it yet.
Use instead updateValueAndValidity()
Upvotes: 2