Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wildcards for listening scope broadcasts with $on on AngularJs

Tags:

angularjs

Is there a way to capture scope broadcasts using wildcards on AngularJS?

Example:

$rootScope.$on('*created', function () { // do stuff });

like image 665
Marcio Cruz Avatar asked Aug 17 '13 00:08

Marcio Cruz


1 Answers

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".

like image 87
Abraham P Avatar answered Nov 05 '22 00:11

Abraham P