AngularJs学习之ng-repeat

  ng-repeat用来遍历一个集合或为集合中的每个元素生成一个模板实例。集合中的每个元素都会被赋予自己的模板和作用域。同时每个模板实例的作用域中都会暴露一些特殊的属性。

 

  $index:遍历的进度(0 ... length-1)

  $first:当元素是遍历的第一个时值为true

  $middle:当元素处于第一个和最后元素之间时为true。

  $last:当元素是遍历的最后一个时值为true。

  $even:当$index值为偶数时值为true。

  $odd:当$index值为奇数时值为true。

 

  使用Directive

<div ng-controller="ImageController">
    <div ng-repeat="image in images" image-repeat-directive>
        <img ng-src="{{image.src}}" />
    </div>
</div>
angular.module('ImageApp', [])
.directive('imageRepeatDirective', function () {
    return function (scope, element, attrs) {
        //angular.element(element);
        if (scope.$last) {
            alert("I am the last!");
        }
    };
});

 

posted @ 2015-09-19 11:11  rubekid  阅读(366)  评论(0编辑  收藏  举报