Is there a way to capture scope broadcasts using wildcards on AngularJS?
Example:
$rootScope.$on('*created', function () {
// do stuff
});
In the angular js source code, $on
is defined as follows:
$on: function(name, listener) {
var namedListeners = this.$$listeners[name];
if (!namedListeners) {
this.$$listeners[name] = namedListeners = [];
}
namedListeners.push(listener);
return function() {
namedListeners[indexOf(namedListeners, listener)] = null;
};
},
since this.$$listeners
is an associative array, and associative arrays in javascript do not take regexs as keys, this suggests that the short answer is "no you can not".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With