[英]angularjs directive template vs templateURL rendering timing
我有一条指令,使用“ templateURL”将外部HTML文件加载为模板。 控制器中有一个函数完全依赖于DOM才能正确执行。 该函数引发错误,因为调用该函数时预期的DOM元素尚未就绪。
JS:
app.directive('directiveName',function(){
return{
restrict:'A',
replace: true,
template: '<div id="elmID"></div>', //** THIS ONE WORKS **//
templateURL:"template.html", //** THIS ONE THROWS AN ERROR **//
scope:false,
link: function(scope, elm, attrs){},
controller:function($scope){
console.log(document.getElementById('elmID'));
}
});
模板:template.html
<div id="elmID"></div>
实际上,我的template.html文件很大,所以我不想使用内联代码。 有人知道可以解决吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.