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(NgFor): $last property support #3991

Closed
wants to merge 1 commit into from

Conversation

alfonso-presa
Copy link
Contributor

Makes a new $last property available during the loop with a boolean
showing if it's the last item in the iteration.

closes: #3102

@@ -76,6 +77,10 @@ export class NgFor {
for (var i = 0; i < insertTuples.length; i++) {
this._perViewChange(insertTuples[i].view, insertTuples[i].record);
}

for (var i = 0, ilen = this.viewContainer.length; i < ilen; i++) {
this.viewContainer.get(i).setLocal('last', i === ilen - 1);
Copy link
Contributor

Choose a reason for hiding this comment

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

What about doing it in _perViewChange() to avoid having to iterate twice ?

ie view.setLocal('last', record.currentIndex === this.viewContainer.length - 1);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That was my very first approach, but it made this expect fail because becoming (and also stop being) the last child of the collection is not considered to be a change by the DefaultIterableDiffer (and I think that's fair) and so the item is not included in the insertTuples.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh right _perViewChange() is only called on records whose indexes have changed.

then LGTM, thanks.

@vicb
Copy link
Contributor

vicb commented Sep 4, 2015

👍

Makes a new `$last` property available during the loop with a boolean
showing if it's the last item in the iteration.

closes: angular#3102
@alfonso-presa alfonso-presa reopened this Sep 4, 2015
@vicb vicb added pr_state: LGTM area: common Issues related to APIs in the @angular/common package action: merge The PR is ready for merge by the caretaker labels Sep 4, 2015
@mary-poppins
Copy link

Merging PR #3991 on behalf of @vicb to branch presubmit-vicb-pr-3991.

@mary-poppins mary-poppins removed the action: merge The PR is ready for merge by the caretaker label Sep 4, 2015
@mhevery mhevery closed this in be95411 Sep 4, 2015
@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 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: common Issues related to APIs in the @angular/common package cla: yes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature request: $last support in ng-for
4 participants