Last active
December 30, 2015 00:39
-
-
Save nuclearghost/7751046 to your computer and use it in GitHub Desktop.
This gist contains an IIFE for finding the number of watches currently found on a page when using Angular.js. It's taken from Words Like Jareds answer on Stack Overflow http://stackoverflow.com/questions/18499909/how-to-count-total-number-of-watches-on-a-page
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment