Cameron Cameron - 7 months ago 8
Javascript Question

What does equals in ngRepeat do?

What does the equals in the

ng-repeat
attribute value mean?

<li ng-repeat="person in people = (people | orderBy: firstname)">


instead of doing:

<li ng-repeat="person in people | orderBy: firstname">


I can't see any examples explaining its use in the documentation for ngRepeat.

Answer

It is usefull for count how many objects were filtered, eg.

function People($scope) {
  $scope.people = [{
    firstname: 'a'
  }, {
    firstname: 'c'
  }, {
    firstname: 'b'
  }, {
    firstname: 'c'
  }]
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>

<div ng-app ng-controller="People">
  <ul>
    <li ng-repeat="person in filteredPeople = (people | filter: 'c')">{{person.firstname}}</li>
  </ul>
  Total filtered: {{ filteredPeople.length }}
</div>