扫码一下
查看教程更方便
表格数据通常是可重复的。ng-repeat 指令可用于轻松绘制表格。
使用 angular 显示表格是非常简单的:
{{ x.name }}
{{ x.country }}
废弃声明 (v1.5)
v1.5 中$http 的 success 和 error 方法已废弃。使用 then 方法替代。
如果你使用的是 v1.5 以下版本,可以使用以下代码:
var app = angular.module('myapp', []); app.controller('customersctrl', function($scope, $http) { $http.get("/demo_source/customers_json.php") .success(function (response) {$scope.names = response.records;}); });
可以使用 css 样式对表格进行样式设置。
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;
}
表格显示序号可以在 中添加 $index:
{{ $index 1 }}
{{ x.name }}
{{ x.country }}
{{ x.name }} {{ x.name }} {{ x.country }} {{ x.country }}