angular.module('app').controller('TheCtrl', function($scope, NotifyingService) {
// ... stuff ...
NotifyingService.subscribe($scope, function somethingChanged() {
// Handle notification
});
});
angular.module('app').factory('NotifyingService', function($rootScope) {
return {
subscribe: function(scope, event, callback) {
var handler = $rootScope.$on(event, callback);
scope.$on('$destroy', handler);
},
notify: function(event) {
$rootScope.$emit(event);
}
};
});