Skip to content

Commit 1f41b30

Browse files
committed
[angular-snipper]drop the watchers on the console as well as their number
1 parent 80d32c3 commit 1f41b30

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

ng-count-watchers.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,26 @@
11
// taken from http://ng.malsup.com/#!/counting-watchers
22
(function countAngularWatchers(angular) {
33
var i, data, scope,
4-
count = 0,
5-
all = document.all,
6-
len = all.length,
7-
test = {};
4+
count = 0,
5+
all = document.all,
6+
len = all.length,
7+
test = {},
8+
watchers = [];
89

910
var mostWatchers = 0;
1011

1112
function countScopeWatchers(scope, element) {
1213
test[scope.$id] = true;
1314
var n = scope.$$watchers.length;
1415
count += n;
16+
if (n > 0){
17+
watchers.push.apply(watchers, scope.$$watchers);
18+
}
1519
if (n > mostWatchers) {
1620
console.log('most watchers', n);
1721
console.log(element);
1822
mostWatchers = n;
23+
1924
}
2025
}
2126

@@ -30,6 +35,6 @@
3035
}
3136
}
3237
}
33-
console.log('this page has', count, 'angular watchers');
38+
console.log('this page has ' + watchers.length + ' angular watchers and the watchers are:', watchers );
3439
return count;
3540
}(window.angular));

0 commit comments

Comments
 (0)