Skip to content

Instantly share code, notes, and snippets.

@enricodeleo
Created June 15, 2016 15:32
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 enricodeleo/09c9814e048fbe682b5258909f6773a9 to your computer and use it in GitHub Desktop.
Save enricodeleo/09c9814e048fbe682b5258909f6773a9 to your computer and use it in GitHub Desktop.
Count Angularjs 1.x watchers
(function countWatchers()
{
var root = angular.element(document.getElementsByTagName('body')).injector().get('$rootScope');
var count = root.$$watchers ? root.$$watchers.length : 0; // include the current scope
var pendingChildHeads = [root.$$childHead];
var currentScope;
while (pendingChildHeads.length)
{
currentScope = pendingChildHeads.shift();
while (currentScope)
{
count += currentScope.$$watchers ? currentScope.$$watchers.length : 0;
pendingChildHeads.push(currentScope.$$childHead);
currentScope = currentScope.$$nextSibling;
}
}
return count;
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment