http://plnkr.co/edit/cJsScs8ixF1aq85Ri7nV?p=preview
过滤器无法正常工作.代码的其他部分也会中断.投掷错误过滤器:notarray.如何修复它
<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>
ng-repeat的文档说:
原文链接:https://www.f2er.com/angularjs/140964.htmltrack by must always be the last expression
所以你需要改变这一行:
<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">
我知道这很模糊,而且这个人会把人赶出去.通常,文档不在您期望的页面上(例如过滤器),但仍然在逻辑位置(例如ng-repeat).它’应该’都在那里.