search

Home  >  Q&A  >  body text

angular.js - About the problem of getting dom in angularjs

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

曾经蜡笔没有小新曾经蜡笔没有小新2840 days ago499

reply all(2)I'll reply

  • 巴扎黑

    巴扎黑2017-05-15 17:07:01

    $element is the jqlite object, just use it.
    An example, a company intern practice example
    https://github.com/ShuyunXIAN...

    reply
    0
  • 世界只因有你

    世界只因有你2017-05-15 17:07:01

    Encapsulate it directly into a carousel component, no need to manipulate and obtain dom or anything.

    reply
    0
  • Cancelreply