Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular, limitTo and track by $index

I am trying to limit an object coming in by filtering (because there will be an option to show all eventually), however I am running into issues when trying to limitTo and track by index. Here is the code :

 <div ng-repeat="item in filter.values track by $index | limitTo:filterLimit" class="cengage-builder-result-filter-value" value="item" update-filter="updateFilter"> 

In the controller:

  $scope.filterLimit = 5; 

It's saying I have dupes in the angular error so I'm thinking the track by $index isn't working here. Can't seem to find a proper way to do this, could use some help. Thanks!

like image 307
ajmajmajma Avatar asked May 12 '15 20:05

ajmajmajma


2 Answers

Filters, like limitTo, orderBy, etc... must come before track by, since they apply to the array source, rather than to the track by expression.

<div ng-repeat="item in filter.values | limitTo:filterLimit track by $index"> 
like image 110
New Dev Avatar answered Oct 03 '22 19:10

New Dev


Try this Use limitTo before track by

 <div ng-repeat="item in filter.values | limitTo:filterLimit track by $index" class="cengage-builder-result-filter-value" value="item" update-filter="updateFilter"> 
like image 29
Harutyun Abgaryan Avatar answered Oct 03 '22 20:10

Harutyun Abgaryan