请看细节.为什么输出错误?
HTML:
<div ng-app> <div ng-controller="TodoCtrl"> <h1>List</h1> <div ng-repeat="t in todos | filter:{ id: '-1'}">{{t.text}}</div> </div> </div>
角码:
function TodoCtrl($scope) { $scope.todos = [{ text: 'learn angular',done: true,id: -1 },{ text: 'learn angular 2',id: -11 },{ text: 'build an angular app',done: false,id: 1 }]; }
输出:
learn angular learn angular 2
请参见:
filter:{ id: ‘-1’}
learn angular 2
我想搜索id -1,但是学习角度2是-11
解决方法
从’-1’删除引号,并将其发送到过滤器进行严格比较.
ng-repeat="t in todos | filter:{ id: -1}:true"