Created
January 27, 2017 12:33
-
-
Save rokerkony/0f106285ce14c4c1d23bb354bad37e9c to your computer and use it in GitHub Desktop.
Get all AngularJS services, factories, constants, ...
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
const items: string[] = []; | |
function allServices (mod: any, r?: any): any { | |
const inj: any = angular.element(document).injector().get; | |
if (!r) { | |
r = {}; | |
} | |
angular.forEach(angular.module(mod).requires, (m: any): any => { | |
allServices(m, r); | |
}); | |
angular.forEach((<any> angular.module(mod))._invokeQueue, (a: any): any => { | |
try { | |
items.push(a[2][0]); | |
r[a[2][0]] = inj(a[2][0]); | |
} catch (e) {} | |
}); | |
return r; | |
} | |
items | |
.sort((a: string, b: string): number => { | |
if (a.toLowerCase() > b.toLowerCase()) { | |
return 1; | |
} else if (a.toLowerCase() < b.toLowerCase()) { | |
return -1; | |
} | |
return 0; | |
}) | |
.forEach(console.log); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment