|
1 | 1 | // taken from http://ng.malsup.com/#!/counting-watchers
|
2 | 2 | (function countAngularWatchers(angular) {
|
3 | 3 | 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 = []; |
8 | 9 |
|
9 | 10 | var mostWatchers = 0;
|
10 | 11 |
|
11 | 12 | function countScopeWatchers(scope, element) {
|
12 | 13 | test[scope.$id] = true;
|
13 | 14 | var n = scope.$$watchers.length;
|
14 | 15 | count += n;
|
| 16 | + if (n > 0){ |
| 17 | + watchers.push.apply(watchers, scope.$$watchers); |
| 18 | + } |
15 | 19 | if (n > mostWatchers) {
|
16 | 20 | console.log('most watchers', n);
|
17 | 21 | console.log(element);
|
18 | 22 | mostWatchers = n;
|
| 23 | + |
19 | 24 | }
|
20 | 25 | }
|
21 | 26 |
|
|
30 | 35 | }
|
31 | 36 | }
|
32 | 37 | }
|
33 | | - console.log('this page has',count,'angular watchers'); |
| 38 | + console.log('this page has '+watchers.length+' angular watchers and the watchers are:',watchers); |
34 | 39 | return count;
|
35 | 40 | }(window.angular));
|
0 commit comments