0

I'm trying to call $rootScope.broadcast from my controller and want to listen it in the directive

Controller:

function startfunction(){
   $rootScope.$broadcast('sharingFn');
}
startfunction();

 Directive:

 $scope.$on('sharingFn',function(){
 console.log('function called");
}    

but the directive is never called here, am i doing something wrong?

rUI7999
  • 129
  • 1
  • 3
  • 20

1 Answers1

0

Do you have a live example of your code? It's difficult to tell where the problem is from the above example.

One potential reason I can think of is the directive doesn't start listening for the event until after the 'sharingFn' event has been broadcast.