Skip to content
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

feat(forms): clear (remove all) components of a FormArray #28918

Closed

Conversation

@renanmontebelo
Copy link
Contributor

commented Feb 22, 2019

Resolves #18531

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • angular.io application / infrastructure changes
  • Other... Please describe:

What is the current behavior?

To remove all elements we have to loop removing the 1st element until empty:

    while (formArray.length) {
      formArray.removeAt(0);
    }

Issue Number: #18531

What is the new behavior?

formArray.clear();

Might be a little faster as updateValueAndValidity() is called only once instead of for each control being removed.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

removeAll may be an alternative name if clear is ambiguous (what are we clearing? values? validators?)

@renanmontebelo renanmontebelo requested a review from angular/fw-forms as a code owner Feb 22, 2019

@googlebot googlebot added the cla: yes label Feb 22, 2019

@benlesh benlesh added the comp: forms label Feb 22, 2019

@ngbot ngbot bot added this to the needsTriage milestone Feb 22, 2019

@renanmontebelo renanmontebelo force-pushed the renanmontebelo:formarray-clear branch from 167fe9e to 39b8d52 Feb 23, 2019

@renanmontebelo renanmontebelo requested a review from angular/fw-public-api as a code owner Feb 23, 2019

@renanmontebelo renanmontebelo force-pushed the renanmontebelo:formarray-clear branch from 39b8d52 to b4e63d4 Feb 23, 2019

@renanmontebelo renanmontebelo changed the title feat(forms): clear (remove all) elements of a FormArray feat(forms): clear (remove all) components of a FormArray Feb 24, 2019

@kara
Copy link
Contributor

left a comment

Thanks for the PR! The change looks good, but needs more docs. Can you also add more information on how to use this new feature to the commit message itself?

Show resolved Hide resolved packages/forms/src/model.ts Outdated
feat(forms): clear (remove all) components from a FormArray
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 #18531

@renanmontebelo renanmontebelo force-pushed the renanmontebelo:formarray-clear branch from b4e63d4 to 6bf3ba8 Feb 28, 2019

@kara

kara approved these changes Feb 28, 2019

Copy link
Contributor

left a comment

LGTM. Thanks for updating the docs!

@kara

This comment has been minimized.

Copy link
Contributor

commented Feb 28, 2019

@kara

This comment has been minimized.

Copy link
Contributor

commented Feb 28, 2019

@IgorMinar Could you take a look at the public API changes?

@nadeem09wani

This comment has been minimized.

Copy link

commented Mar 6, 2019

This PR would be great feature, it will minimize code base and is much cleaner api for performing the task .👍

@IgorMinar

This comment has been minimized.

Copy link
Member

commented Mar 8, 2019

Thanks!

@kara kara closed this in a68b1a1 Mar 8, 2019

@renanmontebelo renanmontebelo deleted the renanmontebelo:formarray-clear branch Mar 8, 2019

wKoza added a commit to wKoza/angular that referenced this pull request Apr 17, 2019

feat(forms): clear (remove all) components from a FormArray (angular#…
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.