Skip to content

Instantly share code, notes, and snippets.

@manar007
Created August 14, 2014 20:27
Show Gist options
  • Save manar007/58c09c29ba31e1c571c4 to your computer and use it in GitHub Desktop.
Save manar007/58c09c29ba31e1c571c4 to your computer and use it in GitHub Desktop.
count angular watchers
(function () {
var root = angular.element(document.getElementsByTagName('body'));
var watchers = [];
var f = function (element) {
if (element.data().hasOwnProperty('$scope')) {
angular.forEach(element.data().$scope.$$watchers, function (watcher) {
watchers.push(watcher);
});
}
angular.forEach(element.children(), function (childElement) {
f(angular.element(childElement));
});
};
f(root);
console.log(watchers.length);
})();
// http://stackoverflow.com/a/18526757/967859
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment