AngularJS Trying to find the total length of a filtered array that uses limitTo

So, I'm trying to get the total length of the filtered array in AngularJS after I used LimitTo so that the application displays more than a certain number of elements at a time. The code is as follows:

<span>Results: {{filtered.length}}</span>
<li ng-repeat = "element in filtered = (array | filter:selectedTag | limitTo:load.number)">

I expect about 150 final results, but I will limit myself to showing 25 pieces. I want the results to display the total length of the filtered array, not just the limited version. Is there any angular code to get this without running the filter again?

+4
source share
2 answers

, , javascript, .

, selectedTag , , .

:

.controler($scope, $filter) {
    // Existing code
    $scope.array = ...
    $scope.selectedTag = ...

    // New code
    $scope.filteredArray = [];

    $scope.$watchCollection('array', function (array) {
        $scope.filteredArray = $filter('filter')(array, $scope.selectedTag);
    });
}

:

<span>Results: {{filteredArray.length}}</span>
<li ng-repeat = "element in filteredArray | limitTo:load.number">

- http://docs.angularjs.org/api/ng.filter:filter

+5

" " ng-repeat. ng-repeat:

PLUNKER DEMO

<div>Total: {{array.length}}</div>
<div>Filtered: {{filtered.length}}</div>

<ul>
  <li ng-repeat="element in (filtered = (array | filter:selectedTag)) | limitTo:load.number">
      {{element}}
  </li>
</ul>

, .

+9

Source: https://habr.com/ru/post/1523719/


All Articles