Question:What are ng-repeat special variables? 

Answer The ng-repeat directive has a set of special variables which you are useful while iterating the collection. These variables are as follows: - $index - $first - $middle - $last
<html> 
  <head> 
   <script src="lib/angular.js"></script> 
   <script> 
     var app = angular.module("app", []); 
    app.controller("ctrl", function ($scope) { 
      $scope.friends = [
       { name: 'shailendra', gender: 'boy' }, 
       { name: 'kiran', gender: 'girl' }, 
       { name: 'deepak', gender: 'boy' }, 
      { name: 'pooja', gender: 'girl' } 
    ];
    }); 
</script> 

 </head>
<body ng-app="app"> 
  <div ng-controller="ctrl"> 
    ul class="example-animate-container"> 
      <li ng-repeat="friend in friends"> 
        
[{{$index + 1}}] {{friend.name}} is a {{friend.gender}}. <span ng-if="$first"> (first element found) </span> <span ng-if="$middle"> (middle element found) </span> <span ng-if="$last"> (last element found) </span>
</li> </ul> </div> </body> </html>
The $index contains the index of the element being iterated. The $first, $middle and $last returns a boolean value depending on whether the current item is the first, middle or last element in the collection being iterated. 

+ Report
Total Preview: 1070
What are ng-repeat special variables?
Copyright © 2024. Powered by Intellect Software Ltd
    
 ul class=example-animate-container> 
  •  [{{$index + 1}}] {{friend.name}} is a {{friend.gender}}.  (first element found)   (middle element found)   (last element found)  
  •   
       The $index contains the index of the element being iterated. The $first, $middle and $last returns a boolean value depending on whether the current item is the first, middle or last element in the collection being iterated. ","http://vcampusbd.com/answers/19163/what-are-ng-repeat-special-variables","http://vcampusbd.com/images/vcampus_quiz.jpg","AngularJS"); }); });