Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 542
Cameron Avatar asked Apr 20 '16 09:04

Cameron


People also ask

How do I remove duplicates in NG-repeat?

You can use unique filter while using ng-repeat . If you use track by $index then unique won't work. ok, I used unique and its working now, thanks!

How does ng-repeat work?

The ng-repeat directive repeats a set of HTML, a given number of times. The set of HTML will be repeated once per item in a collection. The collection must be an array or an object. Note: Each instance of the repetition is given its own scope, which consist of the current item.

How do I get an index value in ng-repeat?

Note: The $index variable is used to get the Index of the Row created by ng-repeat directive. Each row of the HTML Table consists of a Button which has been assigned ng-click directive. The $index variable is passed as parameter to the GetRowIndex function.

What is ngInit?

The ngInit directive allows you to evaluate an expression in the current scope. This directive can be abused to add unnecessary amounts of logic into your templates. There are only a few appropriate uses of ngInit : aliasing special properties of ngRepeat , as seen in the demo below.


1 Answers

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>
like image 164
Krzysztof Safjanowski Avatar answered Oct 20 '22 05:10

Krzysztof Safjanowski