Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- function getWatchers(root) {
- root = angular.element(root || document.documentElement);
- var watcherCount = 0;
- function getElemWatchers(element) {
- var isolateWatchers = getWatchersFromScope(element.data().$isolateScope);
- var scopeWatchers = getWatchersFromScope(element.data().$scope);
- var watchers = scopeWatchers.concat(isolateWatchers);
- angular.forEach(element.children(), function (childElement) {
- watchers = watchers.concat(getElemWatchers(angular.element(childElement)));
- });
- return watchers;
- }
- function getWatchersFromScope(scope) {
- if (scope) {
- return scope.$$watchers || [];
- } else {
- return [];
- }
- }
- return getElemWatchers(root);
- }
- getWatchers().length
- // get all watchers on the whole page
- getWatchers();
- // get watchers of a specific element (and its children)
- getWatchers(document.body);
- // select the element of interest in Chrome Dev tools
- getWatchers($0);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.


