Skip to content

Instantly share code, notes, and snippets.

@anteriovieira
Last active April 11, 2017 13:27
Show Gist options
  • Save anteriovieira/e621911ec7c232e5cd48ab186de2af51 to your computer and use it in GitHub Desktop.
Save anteriovieira/e621911ec7c232e5cd48ab186de2af51 to your computer and use it in GitHub Desktop.
Angular hijacked
var ng = angular.module;
function module() {
var hijacked = ng.apply(this, arguments);
function component() {
}
hijacked.component = component;
return hijacked;
}
angular.module = module;
app.config(['$provide', 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() {
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;
});
}]);
const listDirectivesApp = () => {
const listDirectives = name => {
return angular
.module(name)
._invokeQueue
.filter(item => 'directive' === item[1])
.map(item => item[2][0]);
};
return angular
.modules
.map(listDirectives)
.reduce((acc, l) => acc.concat(l), []);
};
/*
Inside vendor.js
source: http://stackoverflow.com/questions/24889783/angularjs-get-list-of-all-registered-modules
*/
(function(orig) {
angular.modules = [];
angular.module = function() {
if (arguments.length > 1) {
angular.modules.push(arguments[0]);
}
return orig.apply(null, arguments);
}
})(angular.module);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment