Skip to content

Instantly share code, notes, and snippets.

@cubicleDowns
Created November 7, 2014 18:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cubicleDowns/af955d83a14699714818 to your computer and use it in GitHub Desktop.
Save cubicleDowns/af955d83a14699714818 to your computer and use it in GitHub Desktop.
Returns list of scopes. Requires underscore. From here: http://larseidnes.com/2014/11/05/angularjs-the-bad-parts/
function getScopes(root) {
var scopes = [];
function traverse(scope) {
scopes.push(scope);
if (scope.$$nextSibling)
traverse(scope.$$nextSibling);
if (scope.$$childHead)
traverse(scope.$$childHead);
}
traverse(root);
return scopes;
}
var rootScope = angular.element(document.querySelectorAll("[ng-app]")).scope();
var scopes = getScopes(rootScope);
var watcherLists = scopes.map(function(s) { return s.$$watchers; });
_.uniq(_.flatten(watcherLists)).length;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment