In my current scenario, I am faced with a situation where I need to broadcast an event from one controller and have another directive's controller receive the message. The problem arises because the event is sent immediately upon startup of the controller, leading to timing issues due to the asynchronous loading of the view using templateUrl within the directive. This issue would not occur if the view were part of the main page body; however, there could still be potential order of initialization problems with controllers. The code snippet used in my main controller that triggers the broadcast event is as follows:
$rootScope.$broadcast("event:myevent");
I have created a reproduction of the issue on this JSFiddle link.
Upon checking the Javascript console, you can observe that the main controller initializes before the directive's controller does, resulting in the missed event notification by the latter.
Hence, my query is whether it is possible to implement a mechanism that waits until all controllers are initialized before broadcasting an event?
Thank you.