Reputation: 1220
I have a model driven form. On Init I get data from a restservice and put it into my formData Object. I would like to fill my form with this data. Is the only possible solution to this to make something like this?:
...
formData = {}
reproOrderForm: FormGroup;
ngOnInit() {
this.form = this.formBuilder.group({
name: this.formData.name,
});
}
...
Upvotes: 1
Views: 369
Reputation: 658263
You can use one of
this.form.setValue({name: 'somevalue'})
this.form.patchValue({name: 'somevalue'})
this.form.get('name').setValueAndValidity('someValue')
See also https://angular.io/docs/ts/latest/api/forms/index/FormGroup-class.html
Upvotes: 3