AngularJS (19) ng-repeat 特殊變數 $index, $even, $first
angular .module('app',[]) .controller('ctrl',["$scope",function($scope){ $scope.people = [ {name:'Ihc Pig'}, {name:'Lily Pig'}, {name:'AA Pig'}, {name:'BB Pig'} ]; }]);
索引 $index
<body ng-app="app" ng-controller="ctrl">
<p ng-repeat="person in people" ng-class="{item_yellow: $even}">
{ { $index } }. name = { { person.name } }
</p>
</body>
{{$index}}. name = {{person.name}}
偶數列 $even
<body ng-app="app" ng-controller="ctrl">
<p ng-repeat="person in people" ng-class="{item_yellow: $even}">
name = { { person.name } }
</p>
</body>
name = {{person.name}}
奇數列 $odd
<body ng-app="app" ng-controller="ctrl">
<p ng-repeat="person in people" ng-class="{item_yellow: $odd}">
name = { { person.name } }
</p>
</body>
name = {{person.name}}
第一列 $first
<body ng-app="app" ng-controller="ctrl">
<p ng-repeat="person in people" ng-class="{item_yellow: $first}">
name = { { person.name } }
</p>
</body>
name = {{person.name}}
最後一列 $last
<body ng-app="app" ng-controller="ctrl">
<p ng-repeat="person in people" ng-class="{item_yellow: $last}">
name = { { person.name } }
</p>
</body>
name = {{person.name}}
中間列 $middle
<body ng-app="app" ng-controller="ctrl">
<p ng-repeat="person in people" ng-class="{item_yellow: $middle}">
name = { { person.name } }
</p>
</body>
name = {{person.name}}
留言
張貼留言