AngularJs Directives Loaded Event

All we need is an easy explanation of the problem, so here it is.

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.


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.

How to solve :

I know you bored from this bug, So we are here to help you! Take a deep breath and look at the explanation of your problem. We have many solutions to this problem, But we recommend you to use the first method because it is tested & true method that will 100% work for you.

Method 1

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

$timeout(function() { 
    // do something here

Method 2

For the benefit of searchers…

@jack.the.ripper ‘s comment was correct. The SignalR stuff did need moving out to a service.

In the case of notifying when all directives were loaded, this has been working nicely.

Note: Use and implement method 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply