问题
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