示例
下例演示了 ng-repeat 遍历了数组并填充到表格元素中:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>欢迎来到菜鸟教程</title>
<script src="//cdn.bootcss.com/angular.js/1.5.8/angular.min.js"></script>
<style>
.striped {
color:white;
background-color:#f0f;
}
</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" : "小明明",
"Country" : "北京"
},
{
"Name" : "Berglunds",
"Country" : "巴黎"
},
{
"Name" : "小猫",
"Country" : "成都"
},
{
"Name" : "Handel",
"Country" : "西班牙"
}
]
});
</script>
</body>
</html>
尝试一下