I have a FormArray
with some initial controls in it. The user has an option to add controls by clicking a button which triggers the push() method.
I wanna give the user a cancel button which will reset the form to its initial state, removing all added controls.
As of now I am thinking of two approaches:
Option 1: keep track of the index where the controls were added and use the removeAt() method
Option 2: alternatively, I can just reconstruct the entire FormArray
with its initial config.
But is there a simpler way to reset the FormArray to a certain state, something like when we reset the value using setValue() or I have to rebuild it manually using the above options?
To clear all form array values you can use
.clear()
here is the complete code will all possible methods (
add
,remove
,reset
)Template
Working DEMO