加载指令模板后执行Javascript [英] Execute Javascript after directive template has been loaded
本文介绍了加载指令模板后执行Javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我创建了我的自定义指令,用于在angularJS中进行评级.我想在加载html模板后运行javascript.那我该怎么办呢?
I have created my custom directive for rating in angularJS. I want to run javascript after loading of html template. So how can i do that?
我的代码:
app.directive('ratingControl',function(){
return {
restrict:'EA',
templateUrl:'rating.htm',
link :function(scope,element,attr) {}
};
});
推荐答案
在链接中使用$timeout
函数:
// You might need this timeout to be sure it runs after DOM render.
$timeout(function () {
//your code
}, 0,false);
这篇关于加载指令模板后执行Javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文