AngularJS基礎(chǔ) ng-class-odd 指令示例
AngularJS ng-class-odd 指令
AngularJS 實例
為表格的奇數(shù)行設(shè)置 class="striped":
<!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>
運行結(jié)果:
| Alfreds Futterkiste | Germany |
| Berglunds snabbk | Sweden |
| Centro comercial Moctezuma | Mexico |
| Ernst Handel | Austria |
定義和用法
ng-class-odd 指令用于為 HTML 元素動態(tài)的綁定一個或多個 CSS 類,但只作用于奇數(shù)行。
ng-class-odd 指令需要與 ng-repeat 指令搭配使用。
ng-class-odd 指令建議用在表格的樣式渲染中,但是所有HTML元素都是支持的。
語法
<element ng-class-odd="expression"></element>
所有 HTML 元素都支持。
參數(shù)值
| 值 | 描述 |
|---|---|
| expression | 表達指定一個或多個 CSS 類。 |
以上就是對AngularJS資料的整理,有需要的朋友參考下。
相關(guān)文章
詳解AngularJS中module模塊的導(dǎo)入導(dǎo)出
本文給大家介紹angularjs中module模塊的導(dǎo)入導(dǎo)出,涉及到angularjs module相關(guān)知識,對angularjs module感興趣的朋友一起看看吧2015-12-12
Angular自定義組件實現(xiàn)數(shù)據(jù)雙向數(shù)據(jù)綁定的實例
下面小編就為大家分享一篇Angular自定義組件實現(xiàn)數(shù)據(jù)雙向數(shù)據(jù)綁定的實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2017-12-12
Angularjs的ng-repeat中去除重復(fù)數(shù)據(jù)的方法
這篇文章主要介紹了Angularjs的ng-repeat中去除重復(fù)數(shù)據(jù)的方法,涉及AngularJS針對重復(fù)數(shù)據(jù)的遍歷與過濾技巧,需要的朋友可以參考下2016-08-08
AngularJS實現(xiàn)頁面跳轉(zhuǎn)后自動彈出對話框?qū)嵗a
這篇文章主要介紹了AngularJS實現(xiàn)頁面跳轉(zhuǎn)后自動彈出對話框?qū)嵗a,然后在文章下面給大家介紹了angularjs頁面加載后自動彈窗的實例代碼,感興趣的朋友參考下吧2017-08-08
Angular應(yīng)用里異步打開對話框技術(shù)詳解
這篇文章主要為大家介紹了Angular應(yīng)用里異步打開對話框技術(shù)詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2023-12-12

