「AngularJS」ng-class-evenディレクティブを使うサンプル
構文
<要素 ng-repeat="xxx ng-class-even="{expression}">
some code
</要素>
htmlコード
<head> <meta charset="utf-8"> <script src="/angular.js/1.4.6/angular.min.js"></script> <style> .striped { color:white; background-color:black; } </style> </head> <body ng-app="arkApp"> <table ng-controller="myCtrl"> <tr ng-repeat="x in records" ng-class-even="'striped'"> <td>{{x.Name}}</td> <td>{{x.Country}}</td> </tr> </table>
JSコード
var app = angular.module("arkApp", []); app.controller("myCtrl", function($scope) { $scope.records = [ { "Name" : "A001", "Country" : "Germany" }, { "Name" : "B002", "Country" : "Sweden" }, { "Name" : "C003", "Country" : "Mexico" }, { "Name" : "D004", "Country" : "Austria" } ] }); </script>