I'm currently facing a challenge with integrating a FormArray
within another FormArray
. I've been struggling to find a solution for this issue.
Here is the relevant part of my TypeScript file:
createForm() {
this.myForm = this.formBuilder.group({
people: this.formBuilder.array([
{ addresses: this.formBuilder.array([]) }
])
});
}
In essence, I want to create a people FormArray
where each individual can have multiple addresses. In my HTML, I attempt to represent it like so:
<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>
This example is simplified, and my actual form will be more complex. My script includes an "Add person" link that triggers a function pushing an object to the people FormArray
.
Upon calling createForm()
, I encounter the following errors in the browser:
ERROR TypeError: this.form._updateTreeValidity is not a function
ERROR TypeError: this.form.get is not a function
Where did I make a mistake? How can I achieve what I intend to do? Any guidance would be greatly appreciated!