Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularJs Directives Loaded Event

I have just started using AngularJs directives, using the resources here, here and here.

I have a situation where i need to do something after all directives have been loaded.

i.e

Scenario 1

  • Controller Loads
  • Directive 1 loads
  • Directive 2 loads
  • Final event fires (preferably picked up by the controller)

Scenario 2

  • Controller loads
  • Directive 1 loads
  • Directive 2 loads
  • Directive 3 loads
  • Final event fires (preferably picked up by the controller)

I can't seem to find a 'directives loaded' event. With a search, the best I could find was this SO post, (for which this answer does work), but it feels like a 'broad brush' approach.

What is the correct way of doing this please?

Happy to post code if needed, but it doesn't seem beneficial in this instance.

like image 976
JsAndDotNet Avatar asked Jul 11 '14 21:07

JsAndDotNet


1 Answers

You can use $timeout to execute a function after all the directives have been compiled, linked, and rendered.

$timeout(function() { 
    // do something here
});
like image 196
pixelbits Avatar answered Oct 30 '22 17:10

pixelbits