Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ngRepeat: filter not working when using track by $index

This is my html

<body>
<div ng-app="repeatdemo" ng-controller="rd">
<input type="text" ng-model="nameSearch" />
<div ng-repeat="x in names track by $index | filter : nameSearch">
{{x }}
</div>
</div>

This is my script

<script>
var rdapp=angular.module("repeatdemo",[]);
rdapp.controller("rd",function($scope){
$scope.names=['deepu','vicky','hello','hey','vickys'];

});
</script>

When i am using track by $index in repeat option , the filter is not working Please check this fiddle and try removing track by index in ng-repeat

like image 342
Vignesh Subramanian Avatar asked Dec 03 '22 17:12

Vignesh Subramanian


1 Answers

Problem is the order you're applying the filter and the track by in

http://jsfiddle.net/n3xnzvvs/1/

<div ng-repeat="x in names | filter : nameSearch track by $index">
like image 93
shaunhusain Avatar answered Dec 05 '22 05:12

shaunhusain