I have a FormArray with 3 FormGroups and each form group has 2 controls. Im not sure how to access the controls within the form groups to set the form control name.
setting up the form
this.form = this.formBuilder.group({
---a couple controls---
properties: this.formBuilder.array({
first: this.formBuilder.group({
label: new UntypedFormControl(),
value: new UntypedFormControl(),
}),
second: this.formBuilder.group({
label: new UntypedFormControl(),
value: new UntypedFormControl(),
}),
third: this.formBuilder.group({
label: new UntypedFormControl(),
value: new UntypedFormControl(),
}),
})
})
getter for properties form array
get properties() {
return this.form.controls.properties as FormArray;
}
im able to add and delete a row of properties.
html for the form. Am not sure how to access the label and value controls in each form group from the form array.
<div formArrayName="properties">
<ng-container *ngFor="let propertiesForm of properties.controls; let i = index">
<div [formGroupName]="i">
---then I have 3 sets of mat form fields each with and label and value---
</div>
</ng-container>
</div>
formBuilder.arrayaccept parameter which is an array value, but you are providing an object. I don't think this is working. If you want to adapt your object withfirst,secondproperties, you should consider to use theFormGroup.