How to encapsulate single and temporal events in a service?
问题 I'm trying to encapsulate the events in a service in order to implement a mechanics to subscribe / unsubscribe the listeners when a controller's scope is destroyed. This because I have been using the rootScope.$on in the following way: if(!$rootScope.$$listeners['event']) { $rootScope.$on('event', function(ev, data){ // do some... }); } or $scope.$on('$destroy', function(ev, data){ // unsubscribe the listener }); So I just need one listener of this event, I need to delete the existing