Mark Yuan
Mark Yuan

Reputation: 860

How to determine when AngularJS has finished rendering all of the components & directives

Is there any way to run scripts when AngularJS has finished rendering all the routes, components & directives?

For example when all components and directives with a templateURL have finished rendering.

Upvotes: 2

Views: 2626

Answers (3)

Dan M. CISSOKHO
Dan M. CISSOKHO

Reputation: 1075

If it's for display purpose you can use he ngCloak directive.

According to Angular docs it is used to prevent the Angular html template from being briefly being displayed by the browser in its raw (uncompiled) form while your application is loading. Use this directive to avoid the undesirable flicker effect caused by the html template display.

You can also use $http.pendingRequests.

Upvotes: 0

Andrzej Dybionka
Andrzej Dybionka

Reputation: 271

Please use $timeout service with 0ms delay:

$timeout(function() {
   //this code will be invoked when all directives and components will be rendered
});

Upvotes: 0

Daniel Pham
Daniel Pham

Reputation: 146

$timeout is the best way when you need to execute something after the DOM has finished rendering:

$timeout(function() {

});

http://lorenzmerdian.blogspot.de/2013/03/how-to-handle-dom-updates-in-angularjs.html

Upvotes: 0

Related Questions