Reputation: 5451
I want to apply a limit and a filter to my AngularJS loop, but the filter is not working on the entire list, only on the limited list...
I have 100 agreements and I want to show only 20, but I want to add a filter to search on the other 90 agreements...
Edit #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>
Edit #3 :
Upvotes: 0
Views: 1118
Reputation: 262
I think what u written is correct only..may be problem is somewhere else
<tr ng-repeat="agreement in agreements | filter:search | limitTo:20">
just check your input search term properly binded or not...
Upvotes: 1
Reputation: 17064
This HTML code you showed looks good so the problem could be on your input perhaps. This does the trick:
<input type="text" ng-model="search"/>
<table>
<tr ng-repeat="agreement in agreements | filter:search | limitTo:20">
<td>{{agreement}}</td>
</tr>
</table>
Upvotes: 0