1:循环绑定数组
PS:ng-repeat = "i in 数组名" ,i为数组每次循环出来的结果
<!doctype html>
<html ng-app = "myapp" ng-controller = "TestController">
<head>
<script src="http://code.angularjs.org/angular-1.0.1.min.js"></script>
</head>
<body>
<ul ng-repeat = "i in Arr">
<li>{{i}}</li>
</ul>
</body>
<script>
var app = angular.module('myapp', []);
app.controller('TestController', function($scope) {
$scope.Arr = ['arr1','arr2','arr3'];
});
</script>
</html>
2:表格循环绑定二维数组
PS:{{循环步增名[下标]}}
<!doctype html>
<html ng-app = "myapp" ng-controller = "TestController">
<head>
<script src="http://code.angularjs.org/angular-1.0.1.min.js"></script>
</head>
<body>
<table>
<thead>
<tr>
<th>name:</th>
<th>age:</th>
</tr>
</thead>
<tbody>
<tr ng-repeat = "a in ArrT">
<td>{{a[0]}}</td>
<td>{{a[1]}}</td>
</tr>
</tbody>
</table>
</body>
<script>
var app = angular.module('myapp', []);
app.controller('TestController', function($scope) {
$scope.ArrT = [
['jack',15],
['Tom',20],
];
});
</script>
</html>
3:循环绑定对象数组,并且对其进行排序和搜索
PS:{{步增名.对象键名}}
PS: orderBy:['排序对象键名','-排序对象键名'] 可以排序多个条件,如果要倒叙就以 - 开头。
PS: filter:{ } 搜索关键字,可以数字、字符串、对象键值。
PS:$index 这个是自动生成ID的关键以0开始。
<!doctype html>
<html ng-app = "myapp" ng-controller = "TestController">
<head>
<script src="http://code.angularjs.org/angular-1.0.1.min.js"></script>
</head>
<body>
<table>
<thead>
<tr>
<th>ID</th>
<th>name:</th>
<th>age:</th>
<th>work</th>
</tr>
</thead>
<tbody>
<tr ng-repeat = "o in ArrObj | orderBy:['age','-work'] | filter:22 | filter:{Name:Tc} ">
<td>{{$index + 1}}</td>
<td>{{o.Name}}</td>
<td>{{o.Age}}</td>
<td>{{o.work}}</td>
</tr>
</tbody>
</table>
</body>
<script>
var app = angular.module('myapp', []);
app.controller('TestController', function($scope) {
$scope.ArrObj = [
{Name:'jerry',Age:22,work:4},
{Name:'Toonz',Age:13,work:2},
{Name:'Tc',Age:22,work:3},
];
});
</script>
</html>