Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AshCoolman/7b004ee2a33530c2670f to your computer and use it in GitHub Desktop.
Save AshCoolman/7b004ee2a33530c2670f to your computer and use it in GitHub Desktop.
Angular 1.x module access from non-angular code (e.g. console, react etc)
var getService = function (serviceName) {
return angular.element(document.body).injector().get(serviceName);
}
var getRootScope = function () {
return angular.element(document.body).scope().$root;
}
var getScope = function (selector) {
if (!selector) {
return angular.element(document.body).scope().$root; // default rootscope
}
return angular.element(document.querySelector(selector)).scope();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment