I'm creating a filterable table. The first column contains checkboxes for selecting rows, and eventually the user can do some actions with the selections.
On filter, I am doing:
public resetFormRows(items: any[]) {
this.formGroup.removeControl('rows');
const newRows = items.map(_ => new FormControl(false));
const newFormArray = new FormArray(newRows);
this.formGroup.addControl('rows', newFormArray);
}
After filtering the table, I can console.log the controls and see that the FormArray contains the new FormControl. However, when I select the checkbox for a row that shifted (i.e. changed row index), the following error is shown:
ERROR Error: There is no FormControl instance attached to form control element with path: 'rows -> 1'
Here is a stackblitz that demonstrates the bug: https://stackblitz.com/edit/angular-8-template-form-fzsyse?file=src%2Fapp%2Ftable.component.ts
To get the error to show, perform the following:
- Select filter checkbox: "Has Owner?"
- Select checkbox for "Stapler"
I have a few questions:
- why am I getting this error and why does my console.log show a FormControl but the error says I don't have one?
- The error stacktrace doesn't point me to anything specific in my codebase. So, how do people typically debug these issues?
iwith 1, it works, I am not suggesting that's a fix, I am just curious about the behavior