Ng-Class-4

 

Using ng-repeat we dispaly elements of array of object.$odd is true at odd position then odd class is apply to odd elements and even class will apply to other elements.

 
 
 
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Welcome to LearnKode - A code learning platform</title> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.2/angular.min.js"></script> <style> .odd { color: red; } .even { color: green; } </style> </head> <body ng-app="switchExample"> <div ng-controller="ExampleController"> <div class="container"> <table> <thead> <tr ng-repeat="Arr in Arrs"> <th ng-class="{true:'odd',false:'even'}[$odd]"> {{Arr.name}} </th> </tr> </thead> </table> </div> </div> <script> var app = angular.module("switchExample", []); app.controller('ExampleController', ['$scope', function ($scope) { $scope.Arrs = [{ name: "Angular" }, { name: "Jquery" }, { name: "JavaScript" }, { name: "Bootstrap" }] }]); </script> </body> </html>
Output