angular.js - 关于angularjs获取dom的问题
曾经蜡笔没有小新
曾经蜡笔没有小新 2017-05-15 17:05:01
0
2
468

想用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不是应该在渲染完后加载的吗?为什么显示 空呢??求教

曾经蜡笔没有小新
曾经蜡笔没有小新

reply all(2)
巴扎黑

$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.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template