Biswanath
Biswanath

Reputation: 9185

Can angular $timeout be used as a reliable dom ready?

Working with a library which need to be called after dom ready. And I just used the init function with $timeout from the controller's init.

Can $timeout be used as a reliable dom ready event ?

Thanks.

Upvotes: 4

Views: 754

Answers (1)

Michael Kang
Michael Kang

Reputation: 52847

AngularJS will bootstrap the application when the static DOM content is loaded. You can see from the diagram below, that AngularJS also has a dynamic DOM which is built when the directives are compiled and linked.

You can rely on $timeout called from inside of your directive's link function to execute after the $digest cycle has executed and all the models on scope have stabalised:

link: function() {
    $timeout(function() {
       // after $digest
       // dynamic DOM ready
    });
}

Upvotes: 6

Related Questions