Skip to content

Instantly share code, notes, and snippets.

@rokerkony
Created January 27, 2017 12:33
Show Gist options
  • Save rokerkony/0f106285ce14c4c1d23bb354bad37e9c to your computer and use it in GitHub Desktop.
Save rokerkony/0f106285ce14c4c1d23bb354bad37e9c to your computer and use it in GitHub Desktop.
Get all AngularJS services, factories, constants, ...
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