Created
March 25, 2016 13:27
-
-
Save JohannesFerner/eee0841fd93abe48d33a to your computer and use it in GitHub Desktop.
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
'use strict'; | |
angular.module('app.main') | |
.run(function ($rootScope, $timeout, $log) { | |
function countAngularWatchers() { | |
var i, data, scope, | |
count = 0, | |
all = document.all, | |
len = all.length, | |
test = {}; | |
// go through each element. Count watchers if it has scope or isolate scope | |
/* eslint no-for-loops:0 */ | |
for (i = 0; i < len; i++) { | |
/* global angular */ | |
data = angular.element(all[i]).data(); | |
scope = data.$scope || data.$isolateScope; | |
if (scope && scope.$$watchers) { | |
if (!test[scope.$id]) { | |
test[scope.$id] = true; | |
count += scope.$$watchers.length; | |
} | |
} | |
} | |
$log.debug('this page has', count, 'angular watchers'); | |
return count; | |
} | |
$rootScope.$on('$stateChangeSuccess', function (event) { | |
$timeout(function () { | |
countAngularWatchers(); | |
}, 250); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment