-
Notifications
You must be signed in to change notification settings - Fork 25.6k
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
Conversation
b45a573
to
fe18caf
Compare
@@ -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); |
There was a problem hiding this comment.
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);
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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.
👍 |
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
fe18caf
to
1bd44cb
Compare
Merging PR #3991 on behalf of @vicb to branch presubmit-vicb-pr-3991. |
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. |
Makes a new
$last
property available during the loop with a booleanshowing if it's the last item in the iteration.
closes: #3102