The migration from Angular 10 to Angular 15 has caused the following error on the console:
ERROR Error: Cannot find control with path: 'mappedHeaders -> 0 -> value'
example.ts
headerArray: FormArray;
formGroup: FormGroup;
constructor(private fb: FormBuilder) {
this.headerArray = this.fb.array([]);
this.formGroup = this.fb.group({
mappedHeaders: this.headerArray
});
}
printing the structure of this.headerArray on the console post initilization:
printing the structure of this.formGroup on the console after pushing the values:
example.html:
<div [formGroup]="formGroup">
<table>
<tbody formArrayName="mappedHeaders">
<ng-container *ngFor="let header of accountHeaders; index as i">
<tr>
<td>{{i}}</td>
<td [formGroupName]="i">
<select class="ui fluid clearable selection search dropdown column-mapping-dropdown" formControlName="value">
<option *ngFor="let header of fileHeaders" [value]="header">{{ header }}</option>
</select>
</td>
</tr>
</ng-container>
</tbody>
</table>
</div>
the accountHeaders
is an array of strings like ['one', 'two', 'three',...'etc']
The above code works perfectly as expected in Angular 10. I have checked other similar issues but none could address this.
Update The controls are pushed into array post a network call:
const mapped = result['mappedHeaders'];
for (const accountHeader of this.accountHeaders.sort()) {
this.headerArray.push(this.fb.control({
key: accountHeader,
value: mapped[accountHeader]
}));
}
mapped
is a map of key value like ['one': 'one', 'two': 'three']
headerArray
by adding theFormGroup
based onaccountHeaders
array? If yes, can you show the code for initializing it? Otherwise, you may reproduce in StackBlitz. Thanks.