ANGULARJS Basic Ng-class-even instruction usage _angularjs

Source: Internet
Author: User


Angularjs Ng-class-even Instruction



Angularjs instance



Set class= "striped" for even-numbered 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 Result:





Alfreds Futterkiste Germany
Berglunds SNABBK Sweden
Centro Comercial Moctezuma Mexico
Ernst Handel Austria





Definitions and usage



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



Ng-class-even instructions need to be used in combination with ng-repeat instructions.



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



Grammar



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



All HTML elements are supported.



Reference value:



 


value Description
Expression expression specifies one or more CSS classes.





The above is the ANGULARJS data collation, follow-up continue to add, thank you for your support!


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.