Skip to content

Instantly share code, notes, and snippets.

@jurepolutnik
Last active May 8, 2016 19:11
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 jurepolutnik/c798393238f34a7ddc8ca66bc25b036a to your computer and use it in GitHub Desktop.
Save jurepolutnik/c798393238f34a7ddc8ca66bc25b036a to your computer and use it in GitHub Desktop.
function count() {
var root = angular.element(document.querySelector('[ng-app]')).injector().get('$rootScope');
var count = root.$$watchers ? root.$$watchers.length : 0; // include the current scope
var countScopes = 1;
var pendingChildHeads = [root.$$childHead];
var currentScope;
while (pendingChildHeads.length)
{
currentScope = pendingChildHeads.shift();
while (currentScope) {
count += currentScope.$$watchers ? currentScope.$$watchers.length : 0;
countScopes ++;
pendingChildHeads.push(currentScope.$$childHead);
currentScope = currentScope.$$nextSibling;
}
}
console.log("#watchers = " + count);
console.log("#scopes = " + countScopes);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment