首页 > Web开发 > 详细

AngularJs学习之ng-repeat

时间:2015-09-19 12:10:49      阅读:164      评论:0      收藏:0      [点我收藏+]

  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!");
        }
    };
});

 

AngularJs学习之ng-repeat

原文:http://www.cnblogs.com/rubekid/p/4821136.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!