angular track by and orderBy

2019-06-20 06:54发布

Starting to use Angular and playing with a demo. In the model, the event item includes a start time called starts_at and a title.

I had a tag using ng-repeat="event in events track by $index" and tried adding in "|orderBy: event.starts_at" It didn't seem to influence the sorting in any way until I removed the track section.

Does track disables any option for sorting in angular ?

1条回答
我命由我不由天
2楼-- · 2019-06-20 07:12

According to docs: https://docs.angularjs.org/api/ng/directive/ngRepeat filter expressions (and I suspect, order) come before tracking expressions.

Example:

item in items | filter:searchText track by item.id
查看更多
登录 后发表回答