Skip to content

Instantly share code, notes, and snippets.

@curioussavage
Forked from mgol/chrome-angularjs.js
Created July 14, 2014 19:36
Show Gist options
  • Save curioussavage/6f2902cfbe9c279824ed to your computer and use it in GitHub Desktop.
Save curioussavage/6f2902cfbe9c279824ed to your computer and use it in GitHub Desktop.
var ngAppElem = angular.element(document.querySelector('[ng-app]') || document);
window.injector = ngAppElem.injector();
window.inject = injector.invoke;
window.$rootScope = ngAppElem.scope();
Object.defineProperty(window, '$scope', {
get: function () {
var elem = angular.element(__commandLineAPI.$0);
return elem.isolateScope() || elem.scope();
},
});
/**
* USAGE
*
* First copy the script and paste it in Chrome DevTools in Sources -> left pane -> Snippets.
* Then, after loading an Angular page, right click on the snippet and choose "run".
* Afterwards, you have the following available in the console:
*
* 1) $rootScope
* 2) inject(function ($q, $compile) { ...use $q and $compile here... });
* 3) click on an element in DevTools; now $scope in the console points at the element scope (isolate if one exists).
*
* Enjoy!
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment