想用ng 做一个轮播,可是在link 无法获取dom的元素
.directive("carousel",[function (){
return {
replace:true,
restrict:"EA",
scope:{
img:"=myImage"
},
transclude:true,
templateUrl:'../js/template.html',
link:function(scope,elem,attr){
var t=document.querySelectorAll(".carousel ul li");
console.log(t);
}
}
}]);
<p class="carousel">
<ul>
<li ng-repeat="i in img">
<img width="100%" height="100%" src="{{i.img}}" alt=""/>
</li>
</ul>
</p>
link不是应该在渲染完后加载的吗?为什么显示 空呢??求教
$element is the jqlite object, just use it.
An example, a company intern practice example
https://github.com/ShuyunXIAN...
Encapsulate it directly into a carousel component, no need to manipulate and obtain dom or anything.