AngularJS ng-repeat Index

  1. <!DOCTYPE html>  
  2. <html>  
  3.   
  4. <head>  
  5.     <title></title>  
  6.     <meta charset="utf-8" />  
  7.     <script src="Scripts/angular.js"></script>  
  8.     <script>  
  9.     var app = angular.module('app', []);  
  10.     app.controller("MyCtrl", function($scope)  
  11.     {  
  12.         $scope.isSet = function(index)  
  13.           
  14.         {  
  15.             return index % 2 === 0;  
  16.         };  
  17.     })  
  18.     </script>  
  19.     <style>  
  20.     .active   
  21.     {  
  22.         color: red;  
  23.     }  
  24.     </style>  
  25. </head>  
  26.   
  27. <body ng-app="app" ng-controller="MyCtrl">  
  28.     <div>  
  29.         <div ng-repeat="i in [1,2,3,4,5]" ng-class="{'active': isSet($index)}">{{i}}</div>  
  30.     </div>  
  31. </body>  
  32.   
  33. </html>