Cosmin Ionascu Cosmin Ionascu - 1 year ago 102
AngularJS Question

Waiting for all controllers to load during run method

I need to do a broadcast when the page loads. The problem is that the controller never catches the broadcast (my guess is that this is because it hasn't been properly loaded). I have done some research on how to wait for the controllers to be loaded and I've found that I can get a list with all loaded controllers with something like this:

searchApp.controller()._invokeQueue


If I put a breakpoint in the script in the module/controller (the result is roughly the same) I get a list that contains the
$injector
, factory methods -
broadcast
and the
directives
. Even if I am in the controller
_invokeQueue
doesn't contain my controllers.

So how can I wait for the controllers to properly load or get the list of loaded controllers?

Answer Source

Set a variable on the $rootScope and then show/hide your overlay based on that variable. I would suggest that your controller and/or ng-view not be defined on the body tag but rather in a child element that way you can define your overlay outside of that "view".

Here a plunkr showing how it works.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download