fix(forms): inserting and removing controls should work in re-bound form arrays (#21822)

Closes #21501

PR Close #21822
This commit is contained in:
Kara Erickson
2018-01-26 19:15:45 -08:00
committed by Jason Aden
parent 11b12670b2
commit b4cd27979b
2 changed files with 104 additions and 8 deletions
+2 -8
View File
@@ -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();
}
/**