我是Angular JS的新手,我正在尝试创建一个自定义指令,该指令根据url列表创建img标记,然后执行一些DOM操作。我想让图像随着时间的推移淡入淡出,就像幻灯片一样。到目前为止,我已经将图像添加到DOM中,但是我无法在编译或链接函数中找到允许我操作图像的任何地方,因为ng-repeat似乎还没有渲染。有任何想法吗?
指令:
Logger.app.directive("ngSlideshow", function ($compile) {
return {
restrict: "A",
templateUrl: "templates/slideshow.html",
scope: {
pictures: "=ngSlideshow"
},
link: {
post: function(scope, element, attributes) {
var length = $(element).find("img").length; // 0
}
}
};
});
模板:
<div class="spinner">
<img src="{{picture}}" ng-repeat="picture in pictures" alt="" />
</div>
观点:
<div class="pictures" ng-slideshow="log.pictures"></div>
谢谢!
克里斯