LimitTo not working

AngularJS filter LimitTodoes not work in ng-repeat. I created a pagination and then I need to hide only the first two elements. The problem is that pagination was created like track by $index. This filter LimitTodoes not work.

Is there a way to create pagination? I am new to AngularJS so someone help me solve this problem.

<li ng-repeat="i in getNumber(myNumber) track by $index | limitTo: 2" ng-class="{active: $index == selected}" ng-click="select($index)">
   <button ng-click="loadFromMenu($index+1)" ng-class="pageList">
       {{$index+1}}
   </button>
</li>
+4
source share
2 answers

Remove track by $indexbefore the filter and add it after the filter as shown below.

because a filter like limitTo orderBythat should be in front track by $index.

<li ng-repeat="i in getNumber(myNumber)  | limitTo: 2 track by $index" ng-class="{active: $index == selected}" ng-click="select($index)">
   <button ng-click="loadFromMenu($index+1)" ng-class="pageList">
       {{$index+1}}
   </button>
</li>

This will work :)

amuses

+8
source

track by $index ng-repeat

<li ng-repeat="i in getNumber(myNumber) | limitTo: 2"
</li>
0

All Articles