重复 ng-repeat
这算是唯一的一个控制标签么……,它的使用方法类型于:
< div ng - controller = "TestCtrl" > <ul ng - repeat = "member in obj_list" > <li > { { member } } < /li> </ul > </div> var TestCtrl = function($scope){ $scope.obj_list = [1,2,3,4]; }/
除此之外,它还提供了几个变量可供使用:
$index 当前索引
$first 是否为头元素
$middle 是否为非头非尾元素
$last 是否为尾元素
< div ng - controller = "TestCtrl" > <ul ng - repeat = "member in obj_list" > <li > { { $index } }, { { member.name } } < /li> </ul > </div>var TestCtrl = function($scope){ $scope.obj_list = [{name: 'A'}, {name: 'B'}, {name: 'C'}];}/
7.2.2. 赋值 ng-init
这个指令可以在模板中直接赋值,它作用于 angular.bootstrap 之前,并且,定义的变量与 $scope 作用域无关。
< div ng - controller = "TestCtrl"ng - init = "a=[1,2,3,4];" > <ul ng - repeat = "member in a" > <li > { { member } } < /li> </ul > </div>/