0

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 :

My data model

2 Answers 2

1

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...

Sign up to request clarification or add additional context in comments.

3 Comments

check ur get method data in console...in which format its coming
I hope ur doing well only..I can't able to find what is mistake.
can u post ur data model
0

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>

Fiddle

6 Comments

I already have my input see edit #1 ;) An int? It doesn't work with an object?
@tonymx227 Not sure I see the difference, my updated fiddle has an array of objects, is that not what you need?
@tonymx227 Sounds like you have a different issue than in the original question.. now the agreements array is not updated ? or... ? Can you say exactly what's not working ?
The filter is still on the limited list... Not on the entire list of agreements..
Look here, jsfiddle.net/HB7LU/11323 The button adds elements to the list and the view updates automatically. Are you sure you're adding correct elements to agreements ?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.