Filter: notary error in angularjs

http://plnkr.co/edit/cJsScs8ixF1aq85Ri7nV?p=preview

Filter

does not work. The other part of the code also breaks. Throw error filter: notarray. how can this be fixed

<head> <link rel="stylesheet" href="style.css"> </head> <body ng-init="items=[3,1,2,3];"> <h1>Hello Plunker!</h1> <div > </div> <input type="text" ng-model="nm" /> <div ng-repeat="item in items track by $index | filter:nm" ng-hide="hide"> {{item}} </div> <button ng-click="hide=!hide">Toggle </button> <button ng-click="items[items.length]=items.length">Add</button> <script src="https://code.angularjs.org/1.4.2/angular.min.js"></script> <script src="script.js"></script> </body> </html> 
+5
source share
1 answer

The documentation for ng-repeat says:

the track should always be the last expression

So you need to change this line:

 <div ng-repeat="item in items track by $index | filter:nm" ng-hide="hide"> 

:

 <div ng-repeat="item in items | filter: nm track by $index" ng-hide="hide"> 

I know this is unclear, and this man catches people. Often the documentation is not on the page that you expect from it (for example, in a filter), but is still in a logical place (for example, ng-repeat). That should be all.

+24
source

All Articles