Friday, 27 November 2015

Apply track by index and filter for ng-repeat: Angular

Angular default ng-repeat doesn't allow duplicate, for avoiding this you can add track by $index.



<div ng-repeat="user in userList track by $index">
    <span>{{user.name}}</span>
</div>


For applying filter you may try below code



<div ng-repeat="user in userList track by $index | filter:search">
    <span>{{user.name}}</span>
</div>


But it is not correct, filter should be done before applying track by $index.



<div ng-repeat="user in userList | filter:search track by $index">
    <span>{{user.name}}</span>
</div>


Whenever you are applying filter along with track by $index follow above one .You can have multiple filters.

You can read more about track by $index in angular js document

Related Posts

1. Angular js client side pagination like google.

2. Angular Loader using font awesome icons

3. Angular js add class to active element


No comments :

Post a Comment