Skip to content

Instantly share code, notes, and snippets.

@sebastianzillessen
Created April 14, 2015 14:56
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sebastianzillessen/3d2cea1aa5d6433aa2ac to your computer and use it in GitHub Desktop.
Save sebastianzillessen/3d2cea1aa5d6433aa2ac to your computer and use it in GitHub Desktop.
AngularJS decorator to display all $emit and $broadcast events of an application.
angular.module('print-broadcasts', []).config(['$provide', function ($provide) {
$provide.decorator('$rootScope', function ($delegate) {
var _emit = $delegate.$emit;
var _broadcast = $delegate.$broadcast;
$delegate.$emit = function () {
console.log("[$emit] " + arguments[0] + " (" + JSON.stringify(arguments) + ")");
return _emit.apply(this, arguments);
};
$delegate.$broadcast = function () {
console.log("[$broadcast] " + arguments[0] + " (" + JSON.stringify(arguments) + ")");
return _broadcast.apply(this, arguments);
};
return $delegate;
});
}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment