Execute Javascript after directive template has been loaded

こ雲淡風輕ζ 提交于 2019-12-08 04:12:41

问题


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?

my code:

 app.directive('ratingControl',function(){
     return {
         restrict:'EA',
         templateUrl:'rating.htm',
         link :function(scope,element,attr) {}
     };
 });

回答1:


Use $timeout function in link:

// You might need this timeout to be sure it runs after DOM render.
$timeout(function () {
    //your code
}, 0,false); 


来源:https://stackoverflow.com/questions/26945359/execute-javascript-after-directive-template-has-been-loaded

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!