AngularJS - Parity with ngRepeat
Simple example for StackOverflow (http://stackoverflow.com/questions/19502066/in-angularjs-what-is-the-correct-way-to-filter-an-array-based-on-odd-or-even-i)
by Amaury Dalla Monta
October 21, 2013
HTML
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0-rc.3/angular.js"></script>
<div ng-app ng-controller="MyCtrl">
<div
ng-repeat="item in itemsList"
ng-switch="$even"
ng-class-even="'even'"
ng-class-odd="'odd'"
>
<div ng-switch-when="true">{{item}} is even</div>
<div ng-switch-default>{{item}} is odd</div>
</div>
</div>
CSS
.even {
color:red;
}
.odd{
color:green;
}
JavaScript
function MyCtrl($scope) {
$scope.itemsList = ["a", "b", "c", "d", "e", "f"];
}