-
Notifications
You must be signed in to change notification settings - Fork 26.2k
Add support for clearing FormArray #18531
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
+1 |
As per https://angular.io/api/forms/FormArray#adding-or-removing-controls-from-a-form-array this is not recommended. |
@renanmontebelo, yes, you are right. Now I am not recommended this way. If we look at the source of removeAt() method, we can see that for properly way needed to use not only |
As of Angular 8+ please use:
For previous versions the recommended way is
|
@renanmontebelo |
@trotyl you're absolutely right, thank you for your suggestion. I updated my comment based on your feedback. |
…28918) This method is a more convenient and efficient way of removing all components from a FormArray. Before it, we needed to loop the FormArray removing each component until empty. Resolves angular#18531 PR Close angular#28918
While loop will take long time to delete all items if array has 100's of items. You can empty both controls and value properties of FormArray like below. clearFormArray = (formArray: FormArray) => { |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
I'm submitting a...
Current behavior
Current way of clearing FormArray
Expected behavior
rows.length = 0;
Minimal reproduction of the problem with instructions
What is the motivation / use case for changing the behavior?
Environment
The text was updated successfully, but these errors were encountered: