Skip to content

Instantly share code, notes, and snippets.

@tonyjoanes
Created September 26, 2018 09:45
Show Gist options
  • Save tonyjoanes/6f5b96d077385d0cb26c7315f155a5f6 to your computer and use it in GitHub Desktop.
Save tonyjoanes/6f5b96d077385d0cb26c7315f155a5f6 to your computer and use it in GitHub Desktop.
Chrome Snippets for AngularJS
/**
* Setup the angular injector so we can get instances
* of angular objects
* Usage: injector.get('dataContext');
*/
var injector = angular
.element(document.body)
.injector();
/**
* Run the NgStat bookmarklet so we can track watchers and
* digest cycle runs and average times take
* Usage: runNgStat
*/
var runNgStat = function() {
javascript: (function() {
var a = document.createElement("script");
a.src = "https://rawgit.com/kentcdodds/ng-stats/master/dist/ng-stats.js";
a.onload = function() {
window.showAngularStats()
};
document.head.appendChild(a)})();
}
/**
* Get the scope being used within an element
* if none supplied it will just default to 'applicationHost'
*/
var getScopeByElementId = function(elementId) {
elementId = typeof elementId === 'undefined'
? 'applicationHost'
: elementId;
return angular.element(document.getElementById(elementId)).scope();
}
@tonyjoanes
Copy link
Author

Run the snippet as a Chrome browser snippet and then you have access to the functions it creates

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment