You cannot really do that, and that would be an anti-pattern.
Instead, you should create a service that handle events emission and processing so you can do all this logic from there:
module.service('events', function($rootScope) {
var onAllCallbacks = [];
this.broadcast = function(name, data) {
$rootScope.$broadcast(name, data);
onAllCallbacks.forEach(function(cb) { cb(name, data); });
}
this.on = function(name, callback) {
$rootScope.$on(name, callback);
}
this.onAll = function(callback) {
onAllCallbacks.push(callback);
}
})
Then in your code
events.onAll(function(name, data) {
console.log('Broadcasted event:', name, data);
});
events.broadcast('foo', data1);
events.broadcast('bar', data2);
That way you would only use events.broadcast
to broadcast events that you want to be aware of from the onAll
listener.