I am trying to add a FormArray inside another FormArray but can't figure out how to do it.
I have this in my typescript file:
createForm() {
this.myForm = this.formBuilder.group({
people: this.formBuilder.array([
{ addresses: this.formBuilder.array([]) }
])
});
}
Basically, I'm trying to say make a people FormArray where each person can have multiple addresses. I try to render it like this in my html:
<div [formGroup]="myForm">
<div formArrayName="people">
<div *ngFor="let person of people.controls; let i=index">
Person {{ i + 1 }}
<div *ngFor="let address of person.addresses.controls; let j=index">
Address {{ j + 1 }}
</div>
</div>
</div>
</div>
Of course, this is just an example and my actual form will have way more going on. I have an "Add person" link that calls a function in my typescript that pushes an object to the people FormArray.
When I call createForm(), I get the following errors in the browser:
ERROR TypeError: this.form._updateTreeValidity is not a function
ERROR TypeError: this.form.get is not a function
What am I doing wrong? How do I accomplish what I want to do? Any help would be appreciated!