I create a formArray inside form in angular.
When I patch object that has tasks with values as array, seems that this property is ignore and not set.
as expected, the firstname is changed. but the tasks not. why?
I don't want to catch the specific element and use setValue or something similar, I just want to have an object and angular will investigate this object and match the values and the fields.
import { Component, VERSION } from "@angular/core";
import { FormGroup, FormControl, FormArray } from "@angular/forms";
@Component({
selector: "my-app",
template: `
<form [formGroup]="profileForm">
{{ profileForm.value | json }}
<br /><br /><br />
<label>
First Name:
<input type="text" formControlName="firstName" />
</label>
<label>
Last Name:
<input type="text" formControlName="lastName" />
</label>
<button type="button" (click)="clickme()">clickme</button>
</form>
`
})
export class AppComponent {
profileForm = new FormGroup({
firstName: new FormControl(""),
lastName: new FormControl(""),
tasks: new FormArray([])
});
clickme() {
this.profileForm.patchValue({
firstName: "foo",
tasks: [false, true, false]
});
}
}