I'm building a simple AngularJS application. I have an array of objects, e.g.
this.properties = [{
"name": "Jumbo",
...
}, {
"name": "Denegin Keskikankaantie 9 Koy"
...
}, ...]
less than 100 objects in total. I've build a simple search input:
<input type="text" ng-model="vm.searchQuery" />
and used it inside ng-repeat
directive:
<p ng-repeat="property in vm.properties | filter:vm.searchQuery">
{{::property.name}}
</p>
I did this before and everything worked well in other applications. I also tried filter:{name: vm.searchQuery}
.
It has strange behavior, it doesn't show the properties with my searchQuery, e.g. if I type Jumbo, it isn't shown, but... some of them are always shown, e.g. Denegin Keskikankaantie 9 Koy is shown if vm.searchQuery === "Jumbo"
. It's absolutely random all the time.
Does anybody know what might be the reason for this?
Update:
I've updated the plunker from the comments with my data (plunker). It works perfectly. It works on my local server as well. It even works with some users in the production. I have no idea, it should work. I'm just interested and trying to figure out why it doesn't.
Final update: problem found
Sorry, have just looked at the code in production and notice track by $index
in the ng-repeat
directive. That was the reason for this strange behaviour. Removing that fixed the problem.
I'm not sure if I should keep this question because there was a mistake in original question, my
ng-repeat
directive:
<p ng-repeat="property in vm.properties | filter:vm.searchQuery track by $index>
{{::property.name}}
</p>