AngularJS表格詳解及示例代碼
格數(shù)據(jù)本質(zhì)上通常是重復(fù)的。ng-repeat指令,可以用來(lái)方便地繪制表格。下面的示例說(shuō)明使用ng-repeat指令來(lái)繪制表格。
<table>
<tr>
<th>Name</th>
<th>Marks</th>
</tr>
<tr ng-repeat="subject in student.subjects">
<td>{{ subject.name }}</td>
<td>{{ subject.marks }}</td>
</tr>
</table>
表格可以使用CSS樣式設(shè)置樣式,如下:
<style>
table, th , td {
border: 1px solid grey;
border-collapse: collapse;
padding: 5px;
}
table tr:nth-child(odd) {
background-color: #f2f2f2;
}
table tr:nth-child(even) {
background-color: #ffffff;
}
</style>
例子
下面的例子將展示上述所有指令。
testAngularJS.html
<html>
<head>
<title>Angular JS Table</title>
<style>
table, th , td {
border: 1px solid grey;
border-collapse: collapse;
padding: 5px;
}
table tr:nth-child(odd) {
background-color: #f2f2f2;
}
table tr:nth-child(even) {
background-color: #ffffff;
}
</style>
</head>
<body>
<h2>AngularJS Sample Application</h2>
<div ng-app="" ng-controller="studentController">
<table border="0">
<tr><td>Enter first name:</td><td><input type="text" ng-model="student.firstName"></td></tr>
<tr><td>Enter last name: </td><td><input type="text" ng-model="student.lastName"></td></tr>
<tr><td>Name: </td><td>{{student.fullName()}}</td></tr>
<tr><td>Subject:</td><td>
<table>
<tr>
<th>Name</th>
<th>Marks</th>
</tr>
<tr ng-repeat="subject in student.subjects">
<td>{{ subject.name }}</td>
<td>{{ subject.marks }}</td>
</tr>
</table>
</td></tr>
</table>
</div>
<script>
function studentController($scope) {
$scope.student = {
firstName: "Mahesh",
lastName: "Parashar",
fees:500,
subjects:[
{name:'Physics',marks:70},
{name:'Chemistry',marks:80},
{name:'Math',marks:65},
{name:'English',marks:75},
{name:'Hindi',marks:67}
],
fullName: function() {
var studentObject;
studentObject = $scope.student;
return studentObject.firstName + " " + studentObject.lastName;
}
};
}
</script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js"></script>
</body>
</html>
輸出
在Web瀏覽器打開(kāi)textAngularJS.html,看到以下結(jié)果:

以上就是AngularJS表格基礎(chǔ)知識(shí)的整理,后續(xù)繼續(xù)整理相關(guān)知識(shí),謝謝大家對(duì)本站的支持!
- AngularJS表格添加序號(hào)的方法
- AngularJS 與Bootstrap實(shí)現(xiàn)表格分頁(yè)實(shí)例代碼
- AngularJS入門教程之表格實(shí)例詳解
- angularjs表格ng-table使用備忘錄
- AngularJS中的Directive自定義一個(gè)表格
- 如何用angularjs制作一個(gè)完整的表格
- angularjs表格分頁(yè)功能詳解
- 使用angularjs創(chuàng)建簡(jiǎn)單表格
- 詳解AngularJS中的表格使用
- AngularJS基礎(chǔ)知識(shí)筆記之表格
- AngularJS表格樣式簡(jiǎn)單設(shè)置方法示例
相關(guān)文章
angularjs在ng-repeat中使用ng-model遇到的問(wèn)題
本文給大家分享了一個(gè)個(gè)人在使用angular過(guò)程中遇到的在ng-repeat中使用ng-model的問(wèn)題,并附上簡(jiǎn)單的解決辦法,希望能對(duì)大家學(xué)習(xí)angular有所幫助2016-01-01
測(cè)試IE瀏覽器對(duì)JavaScript的AngularJS的兼容性
這篇文章主要介紹了測(cè)試IE瀏覽器對(duì)JavaScript的AngularJS的兼容性的方法,盡管隨著Windows10的近期上市,IE瀏覽器即將成為歷史...需要的朋友可以參考下2015-06-06
Angular實(shí)現(xiàn)二級(jí)導(dǎo)航欄
這篇文章主要為大家詳細(xì)介紹了Angular實(shí)現(xiàn)二級(jí)導(dǎo)航欄,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-03-03
angularjs點(diǎn)擊圖片放大實(shí)現(xiàn)上傳圖片預(yù)覽
這篇文章主要為大家詳細(xì)介紹了angularjs點(diǎn)擊圖片放大實(shí)現(xiàn)上傳圖片預(yù)覽的相關(guān)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-02-02
angular4實(shí)現(xiàn)tab欄切換的方法示例
本篇文章主要介紹了angular4實(shí)現(xiàn)tab欄切換的方法示例,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-10-10
深入理解Angularjs中的$resource服務(wù)
大家可以知道在Angularjs中可以用$http同服務(wù)器進(jìn)行通信,功能上比較簡(jiǎn)單,AngularJS還提供了另外一個(gè)可選的服務(wù)$resource,使用它可以非常方便的同支持restful的服務(wù)單進(jìn)行數(shù)據(jù)交互。這篇文章主要給大家深入的介紹了Angularjs中的$resource服務(wù)。2016-12-12
基于angularjs實(shí)現(xiàn)圖片放大鏡效果
這篇文章給大家分享了angularjs實(shí)現(xiàn)購(gòu)物放大鏡效果的源碼實(shí)例,代碼介紹的很詳細(xì),有需要的可以參考借鑒,下面來(lái)一起看看。2016-08-08

