Skip to content

Instantly share code, notes, and snippets.

@supertinou
Created April 22, 2016 21:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save supertinou/c468723498615f2a9cea47399389c4b5 to your computer and use it in GitHub Desktop.
Save supertinou/c468723498615f2a9cea47399389c4b5 to your computer and use it in GitHub Desktop.
AngularJS : Capture and console log all broadcasts
.config(function($provide) {
$provide.decorator("$rootScope", function($delegate) {
var Scope = $delegate.constructor;
var origBroadcast = Scope.prototype.$broadcast;
var origEmit = Scope.prototype.$emit;
Scope.prototype.$broadcast = function($scope) {
console.log("$broadcast was called on $scope " + $scope.$id + " with arguments:",
arguments);
return origBroadcast.apply(this, arguments);
};
Scope.prototype.$emit = function($scope) {
console.log("$emit was called on $scope " + $scope.$id + " with arguments:",
arguments);
return origEmit.apply(this, arguments);
};
return $delegate;
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment