Skip to content

Instantly share code, notes, and snippets.

@nathanwoulfe
Created February 6, 2020 01:52
Show Gist options
  • Save nathanwoulfe/26cf88468cb242ba16537adb480e7f98 to your computer and use it in GitHub Desktop.
Save nathanwoulfe/26cf88468cb242ba16537adb480e7f98 to your computer and use it in GitHub Desktop.
Log all events in an AngularJs application
angular.module('myModule', [])
.config(['$provide', $provide => {
$provide.decorator("$rootScope", function ($delegate) {
var Scope = $delegate.constructor;
var origBroadcast = Scope.prototype.$broadcast;
var origEmit = Scope.prototype.$emit;
Scope.prototype.$broadcast = function () {
console.log("$broadcast was called on $scope " + Scope.$id + " with arguments:", arguments);
return origBroadcast.apply(this, arguments);
};
Scope.prototype.$emit = function () {
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