Skip to content

Instantly share code, notes, and snippets.

@bhashkarsharma
Created August 2, 2016 13:03
Show Gist options
  • Save bhashkarsharma/a8425cf8050237ea78d0a715d95d360e to your computer and use it in GitHub Desktop.
Save bhashkarsharma/a8425cf8050237ea78d0a715d95d360e to your computer and use it in GitHub Desktop.
Count the number of angular watchers
(function () {
var elements = document.getElementsByClassName('ng-scope');
var watches = [];
var visited_ids = {};
for (var i=0; i < elements.length; i++) {
var scope = angular.element(elements[i]).scope();
if (scope.$id in visited_ids)
continue;
visited_ids[scope.$id] = true;
watches.push.apply(watches, scope.$$watchers);
}
return watches.length;
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment