Angular
Intro to Reactive Forms in Angular - Make Forms Dynamic

Demo: Removing Items from a FormArray

Mute
Current Time 0:00
/
Duration Time 0:00
Loaded: 0%
Progress: 0%
Stream TypeLIVE
Remaining Time -0:00
 
PRO

In the last video, we learned how to add a FormControl to a FormArray. Now we’ll learn how to remove them.

First, we'll add a new method called removePhoneNumber(), which takes a parameter of index so that we can specify which formControl we’re removing from the array. We'll then use the FormArray method removeAt(), passing the index. removePhoneNumber(index: number): void { this.phoneNumbers.removeAt(index); }

In the template, add a click event on the remove_button on line 15, passing in the index i we defined in the *ngFor:
(click)="removePhoneNumber(i)"

 

I finished! On to the next chapter