Skip to content

Instantly share code, notes, and snippets.

@aramalipoor
Created November 4, 2015 08:43
Show Gist options
  • Save aramalipoor/a9626a8d32b559b103ce to your computer and use it in GitHub Desktop.
Save aramalipoor/a9626a8d32b559b103ce to your computer and use it in GitHub Desktop.
AngularJS 1.x $watch counter
(function () {
var root = $(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($(childElement));
});
};
f(root);
console.log(watchers.length);
})();
@aramalipoor
Copy link
Author

You can paste this in your Chrome console and see the results ;)

@ahmadrabie
Copy link

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment