作用:遍历数组
<body ng-app = 'app' ng-controller = 'wmxController'>
<ul>
<!--item可以随意命名,in是固定写法,不能改。array是控制器中定义的数组名称,要保持一致-->
<li ng-repeat="item in array"> {{item}} </li>
</ul>
<hr>
<ul>
<li ng-repeat="student in stu"> {{student.name}}----{{student.age}} </li>
</ul>
<script src="angular.js"></script>
<script>
var app = angular.module('app',[]);
app.controller('wmxController',['$scope',function ($scope) {
// 定义一个全局的数组,名称为array,这个数组中分别有三个json对象
$scope.array = ['2017年','你好','我喜欢你'];
$scope.stu = [
{name:'xiao',age:18},
{name:'cao',age:20},
{name:'mei',age:22}
];
}])
</script>
</body>
网友评论