Supporting trackBy:<expression|id>
See original GitHub issueI’m submitting a … (check one with “x”)
[ ] bug report => search github for a similar issue or PR before submitting
[X] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question
- Angular version: 2.1.2
What is the motivation / use case for changing the behavior?
Related to the discussion here http://stackoverflow.com/questions/36322829/how-to-use-track-by-inside-ngfor-angular-2, I’d like to propose supporting just stating a property name (alternatively inline function) for trackBy. The use case is that ngFor
and trackBy
are very common , and the current requirement of having to specify a function is confusing, terse, and arguably worse than Angular 1. Thus, I’d wish something like this to work
<li *ngFor="let item of items; trackBy:'id'">
{{item.whatever}}
</li>
and/or
<li *ngFor="let item of items; trackBy:item.id">
{{item.whatever}}
</li>
Issue Analytics
- State:
- Created 7 years ago
- Reactions:76
- Comments:16 (6 by maintainers)
Top Results From Across the Web
Support for Track-It! - BMC Software
Get support for Track-It!, including documentation, frequently asked questions, knowledge articles, downloads, training, and more.
Read more >On Track Support Services
You can focus on driving and leave the rest to us – we provide complete track support for both car and driver. From...
Read more >What to expect from Toggl Track Support?
Toggl Track Support can be reached via the support@track.toggl.com email address, the Contact page, or by using feedback forms available in various Toggl ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I don’t get why this should be so complicated. Really, guys, KIS. We just need to extend the ngForTrackBy signature to be less pedantic:
Done. No fancy compiler stuff needed. And it’s type safe because of keyof.
trackBy: '$index'
ortrackBy: 'propName'
seem to be simple enough to grasp.Disclaimer! I’m the author of NgForTrackByProperty
Angular global trackBy directive by passing a property name for track the ngFor item with strict type checking.
Online demo
Source code