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
wants to merge 1 commit into from
Closed

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

wants to merge 1 commit into from

Conversation

renanmontebelo
Copy link
Contributor

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 a team as a code owner February 22, 2019 05:09
@ngbot ngbot bot added this to the needsTriage milestone Feb 22, 2019
@renanmontebelo renanmontebelo requested a review from a team as a code owner February 23, 2019 01:22
@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
Copy link
Contributor

@kara kara left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

packages/forms/src/model.ts Outdated Show resolved Hide resolved
@kara kara added action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews target: major This PR is targeted for the next major release labels Feb 26, 2019
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
Copy link
Contributor

@kara kara left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks for updating the docs!

@kara
Copy link
Contributor

kara commented Feb 28, 2019

presubmit

@kara kara added action: review The PR is still awaiting reviews from at least one requested reviewer action: presubmit The PR is in need of a google3 presubmit and removed action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews labels Feb 28, 2019
@kara kara assigned IgorMinar and unassigned renanmontebelo Feb 28, 2019
@kara
Copy link
Contributor

kara commented Feb 28, 2019

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

@nhwaani
Copy link

nhwaani 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
Copy link
Contributor

Thanks!

@kara kara added action: merge The PR is ready for merge by the caretaker and removed action: presubmit The PR is in need of a google3 presubmit action: review The PR is still awaiting reviews from at least one requested reviewer labels Mar 8, 2019
@kara kara closed this in a68b1a1 Mar 8, 2019
@renanmontebelo renanmontebelo deleted the formarray-clear branch March 8, 2019 04:10
wKoza pushed a commit to wKoza/angular that referenced this pull request Apr 17, 2019
…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
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 14, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker area: forms cla: yes target: major This PR is targeted for the next major release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for clearing FormArray
6 participants