Angularjs ng-class-odd Instruction
Angularjs instance
Set class= "striped" for odd rows in a table:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="http://apps.bdimg.com/libs/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>{{x.Country}}</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>
Run Result:
Alfreds Futterkiste |
Germany |
Berglunds SNABBK |
Sweden |
Centro Comercial Moctezuma |
Mexico |
Ernst Handel |
Austria |
Definitions and usage
The ng-class-odd directive is used to bind one or more CSS classes dynamically for HTML elements, but only for odd-numbered rows.
ng-class-odd instructions need to be used in combination with ng-repeat instructions.
The ng-class-odd directive is recommended for use in table style rendering, but all HTML elements are supported.
Grammar
<element ng-class-odd= "expression" ></element>
All HTML elements are supported.
Parameter values
value |
Description |
Expression |
expression specifies one or more CSS classes. |
The above is the collation of ANGULARJS data, there is a need for friends under the reference.