...">

What to do in ngRepeat?

What does equals mean in ng-repeat attribute value?

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

instead of doing:

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

I see no examples explaining its use in the documentation for ngRepeat.

+7
javascript angularjs
source share
2 answers

It is useful to calculate how many objects have been filtered, for example.

 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> 
+8
source share

@Krzysztof. There is no need to use the "=" operator to display the number of filtered objects. This can be done without it. So you are completely wrong.

 <html> <head> <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.8/angular.min.js"></script> </head> <body ng-app="myApp" ng-controller="myCtrl"> <p ng-repeat="x in people | orderBy: 'age'">{{x.name}},{{x.age}}</p> <p>Total Filtered: {{people.length}}</p> <script> //Module declaration var app = angular.module('myApp',[]); //controller declaration app.controller('myCtrl',function($scope,$timeout){ $scope.people = [{name:"Peter",age:15},{name:"Julie",age:28},{name:"Roger",age:17}]; }); </script> </body> </html> 
-2
source share

All Articles