English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

AngularJS ng-class-odd directive

AngularJS Reference Manual

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="https://cdn.staticfile.org/angular.js/1.4.6/angular.min.js"></script>
<style>
.striped {
    color:white;
    background-color:black;
}
</style>
</head>
<body ng-app="myApp">
<table ng-controller="myCtrl">
<tr ng-repeat="x in records" ng-class-odd="'striped'">
  <td>{{x.Name}}</td>/td>
  <td>{{x.Country}}</td>/td>
</tr>
</table>
<script>
var app = angular.module("myApp", []);
app.controller("myCtrl", function($scope) {
  $scope.records = [
    {
      "Name": "Alfreds Futterkiste",
      "Country": "Germany"
    }
    {
      "Name": "Berglunds snabbk"
      "Country": "Sweden"
    }
    {
      "Name": "Centro comercial Moctezuma",
      "Country": "Mexico"
    }
    {
      "Name": "Ernst Handel",
      "Country": "Austria"
    }
  ]
});
</script>
</body>
</html>
Test to see ‹/›

Definition and Usage

ng-class-odd The directive is used to dynamically bind one or more CSS classes to an HTML element, but it only acts on odd rows.

ng-class-odd The directive needs to be used with ng-repeat used together.

ng-class-odd The directive is recommended for use in table style rendering, but all HTML elements are supported.

Syntax

   <element ng-class-odd="expression"></element>

All HTML elements support it.

Parameter Value

ValueDescription
expressionExpress a specified one or more CSS classes.

AngularJS Reference Manual