I want to use ng to make a carousel, but I can’t get the dom elements in the link
.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>
Shouldn’t the link be loaded after rendering? Why does it show empty? ? Asking for advice
$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.