I'm trying to use reactive forms and a formArray to create some forms, but i'm trying and I get this error "FormArray. Cannot find control with path"
I need to bind these fields and update my array to send back to the api later.
I tried changing names, the formcontrolname, formcontrol, formArrayName.
ngOnInit() {
this.formGroundUse = this.fb.group({
published: true,
groundUses: this.fb.array([])
});
this.dataModel = Object.create(null);
const groudUse = this.formGroundUse.controls.groundUses as FormArray;
this.tableData.forEach((item, index) => {
groudUse.push(
this.fb.group({
title: new FormControl(item.title),
value: new FormControl(item.value),
percentage: new FormControl(item.percentage)
})
);
console.log(groudUse);
});
this.formGroundUse.valueChanges
.subscribe(data => {
this.dataModel = data;
console.log('listening');
});
}
<ng-container formArrayName="groundUses"
*ngFor="let data of formGroundUse.controls['groundUses']?.controls; let i = index">
<tr [formGroup]="groundUses.controls[i]">
<!-- *ngFor="let data of tableData"> -->
<td class="table-subtitle">{{data.title}} {{i}}</td>
<td class="input-container">
<label for="">Área (Ha)</label>
<!-- formControlName="{{data.title}}" -->
<input type="text" [disabled]="!technicalData.edit" class="form-input" [value]="data.value"
(change)="updateItem($event)" formControlName="value">
</td>
<td>{{data.percentage}}</td>
</tr>
</ng-container>
I need to bind these fields to my ts to create some calculations, but i'm getting just the old value in the dataModel.