I had same problem. There are two ways to solve this issue.
Preserve subscription
You can manually clear each FormArray element by calling the removeAt(i) function in a loop.
clearFormArray = (formArray: FormArray) => {
while (formArray.length !== 0) {
formArray.removeAt(0)
}
}
The advantage to this approach is that any subscriptions on your
formArray, such as that registered withformArray.valueChanges, will not be lost.
See the FormArray documentation for more information.
Cleaner method (but breaks subscription references)
You can replace whole FormArray with a new one.
clearFormArray = (formArray: FormArray) => {
formArray = this.formBuilder.array([]);
}
This approach causes an issue if you’re subscribed to the
formArray.valueChangesobservable! If you replace the FromArray with a new array, you will lose the reference to the observable that you’re subscribed to.