title: how to broadcast an event when my template is loaded?
body: <p>EDIT:it seems I messed things up, the directive is executed after the template is loaded anyway, I'll sort this out and edit my question when I have more time</p>
  
  <p>I'm doing a conditional loading of templates/views with ui-router and then I want to apply a directive to modify the HTML of these template. I figured I would broadcast an event when the template is loaded and condition the directive onto this event. But can't get it to work.</p>
  
  <p>This is how I load my templates:</p>
  
  <pre><code>FlatView.config(function($stateProvider, $urlRouterProvider) {
  
      $urlRouterProvider.otherwise("");
  
      $stateProvider
        .state('flatView', {
            url:"",
  
            views: {
                'main': {
                    controller:"flatViewElementList",
                    templateUrl:Routing.generate('_NRtworks_FlatView_elementList') 
                },
                'discrimSelector': {
                    controller:"flatViewElementList",
                    templateProvider:['BDParameters','$http','$rootScope',function(BDParameters,$http,$rootScope){
  
                      return BDParameters.then(function (result) {
                          //console.log(result);
                          if(result["selectorList"] === 0)
                          {
                              return "";
                          }
                          else
                          {                            
                              return $http.get(Routing.generate('_NRtworks_FlatView_DiscrimSelector')).then(function(result)
                              {
                                  //console.log(result.data);
                                  $rootScope.$broadcast("NRtworks_DiscrimSelect");
                                  return result.data;
                              });                           
                          }
                      });
  
                      //return Routing.generate('_NRtworks_FlatView_DiscrimSelector');
  
                    }],
                      resolve:
                      {
                          test:function(BDParameters,$rootScope){
                              $rootScope.$broadcast("NRtworks_DiscrimSelect");
                            }
                      }
                }
            }
        });    
  });
  </code></pre>
  
  <p>And this is the directive:</p>
  
  <pre><code>FlatView.directive('NRtworks_discrimSelect',function($rootScope){
      var linkFunction = function(scope, element, attributes)
      {       
          $scope.$on("NRtworks_DiscrimSelectLoaded", function(){
                      transformDiscrimSelect(element);
          });
  
          function transformDiscrimSelect(element)
          {
              console.log("occured");
              element.on('change',function(event){
                  //do stuff
              });
          };
  
      };
      return{
          restrict: 'AEC',
          link:linkFunction
      };}
  );
  </code></pre>
  
  <p>First, is the event system the right way to handle this ? If yes then what am I doing wrong ? If no, well, I'm open to suggestions ;)</p>