Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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;
currentScope = currentScope.$$nextSibling;
return count;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.