AngularJS Basic ng class even Directive Usage

  • 2021-07-07 06:04:09
  • OfStack

AngularJS ng-class-even Directive

AngularJS instance

Set class= "striped" for even rows of the 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-even="'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 results:

Alfreds Futterkiste Germany
Berglunds snabbk Sweden
Centro comercial Moctezuma Mexico
Ernst Handel Austria

Definition and usage

The ng-class-even directive is used to dynamically bind one or more CSS classes for an HTML element, but only for even-numbered rows.

The ng-class-even instruction needs to be used with the ng-repeat instruction.

The ng-class-even directive is recommended for style rendering of tables, but all HTML elements are supported.

Grammar

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

All HTML elements are supported.

Reference value:

描述
expression 表达指定1个或多个 CSS 类。

The above is the collation of AngularJS data, and the follow-up will continue to be supplemented. Thank you for your support!


Related articles: