我想对我的AngularJS循环应用限制和过滤器,但过滤器不在整个列表上工作,只在有限的列表上...
我有100个协议,我想只显示20个,但我想添加一个过滤器来搜索其他90个协议......
编辑#2:
app.controller("AgreementsController", function($scope, $http) {
$scope.agreements = [];
$http.get('/api/agreement').success(function(data, status, headers, config) {
$scope.limit = data.limit;
data.agreements.forEach( function(agr){
$scope.agreements.push(agr);
});
});
});
<input type="text" ng-model="search">
<table>
<thead>
<tr>
<th>number</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="agreement in agreements | filter:search | limitTo:5">
<td>{{agreement.number}}</td>
</tr>
</tbody>
</table>
编辑#3:
答案 0 :(得分:0)
您展示的HTML代码看起来很好,所以问题可能出在您的输入上。这就是诀窍:
<input type="text" ng-model="search"/>
<table>
<tr ng-repeat="agreement in agreements | filter:search | limitTo:20">
<td>{{agreement}}</td>
</tr>
</table>
答案 1 :(得分:0)
我认为你写的只是正确的......可能是问题在别的地方
<tr ng-repeat="agreement in agreements | filter:search | limitTo:20">
只是检查输入搜索字词是否正确绑定...