I have some code that was working in a controller. I refactored and moved that functionality into a service. The code had an event listener:
$rootScope.$on( .....)
This was caught when it was in the controller, but does not catch the event when in a service. I have tried using $rootScope.$broadcast()
and $rootScope.$emit()
to signal the event but neither are caught in the service.
There is nothing special about the service code:
heartbeatService.$inject = [ '$rootScope', 'vcapChanService', 'eventService', 'logger' ];
function heartbeatService( $rootScope, vcapChanService, eventService, logger ) {
//....
}
Question: how do I get a service to catch events on the root scope?
Edit with more info: The event is signaled from another service. And this event is caught in other controllers, but is NOT caught in another service. I have tried all variations of service/factory, emit/broadcast, etc. and none of them work. The service just does not catch the event but in all other regards works perfectly.