title: Angular: running function in controller when all directives are loaded
body: <p>I'm trying to come up with some code which allows me to run a function in the controller but only once the whole dom is setup and ready (including the directives link function run etc.). </p>
  
  <p>I'm currently communicating between ctrl/service and the directive via $rootScope broadcasts. The first broadcast at the time of the controller loading is not being picked up by the directive. The reason is of course that the controller loads before the directive link function runs. I've read a few similar questions on SO where people recommended on using $timeout for these calls. This unfortunately doesn't always work and I don't want to clutter my ctrl/services with lots of $timeout calls. Therefore I'm looking for another solution to my problem.</p>
  
  <p>Communication pattern is as follows:</p>
  
  <p>1.) Controller tells Service to prepare some data (via function call in service)</p>
  
  <p>2.) Service tells directive to display data (via broadcast)</p>
  
  <p>3.) Directive displays data ...or not in my case :(</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>As timing is essential in my app, I'm basically looking for a way to initiate a function in the controller as soon as all angular components have finished loading. That function in the controller will display content by assigning a value to a scope variable. At the same time it will start taking the time. I can of course only start doing that once the directives are loaded, otherwise the tmining is wrong or the directive is not yet ready to display content etc.</p>
  
  <p>I've read through a blog post by Ben Nadel, which basically shows how directives are loaded. I was hoping to setup an outer directive which loads last so I can trigger the finished loading from there. Unfortunately that doesn't work as soon as any of the inner directives use a templateUrl.
  <a href="http://www.bennadel.com/blog/2603-directive-controller-and-link-timing-in-angularjs.htm" rel="nofollow">http://www.bennadel.com/blog/2603-directive-controller-and-link-timing-in-angularjs.htm</a></p>