fix(forms): inserting and removing controls should work in re-bound form arrays (#21822)
Closes #21501 PR Close #21822
This commit is contained in:
committed by
Jason Aden
parent
11b12670b2
commit
b4cd27979b
@@ -1311,25 +1311,19 @@ export class FormArray extends AbstractControl {
|
||||
this._onCollectionChange();
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert a new {@link AbstractControl} at the given `index` in the array.
|
||||
*/
|
||||
/** Insert a new {@link AbstractControl} at the given `index` in the array. */
|
||||
insert(index: number, control: AbstractControl): void {
|
||||
this.controls.splice(index, 0, control);
|
||||
|
||||
this._registerControl(control);
|
||||
this.updateValueAndValidity();
|
||||
this._onCollectionChange();
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the control at the given `index` in the array.
|
||||
*/
|
||||
/** Remove the control at the given `index` in the array. */
|
||||
removeAt(index: number): void {
|
||||
if (this.controls[index]) this.controls[index]._registerOnCollectionChange(() => {});
|
||||
this.controls.splice(index, 1);
|
||||
this.updateValueAndValidity();
|
||||
this._onCollectionChange();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user