Created
February 6, 2020 01:52
-
-
Save nathanwoulfe/26cf88468cb242ba16537adb480e7f98 to your computer and use it in GitHub Desktop.
Log all events in an AngularJs application
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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