Friday, 12 July 2019

Working With Rreactive Forms - Deleting all items in a FormArray Angular 8

> Angular 8 Samples

As of Angular 8, there's a new way of clearing all items in a FormArray.

(this.recipeForm.get('ingredients')).clear();
 

The clear() method automatically loops through all registered FormControls (or FormGroups) in the FormArray and removes them.

It's like manually creating a loop and calling removeAt() for every item.