Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Performance bookmarklet for Angularjs
var bindings = document.getElementsByClassName('ng-binding').length;
var scopes = document.getElementsByClassName('ng-scope').length;
var bodyScope = angular.element(document.querySelector('body')).scope();
var watchers = bodyScope && bodyScope.$$watchers ? bodyScope.$$watchers.length : '?';
var getWatchers = function () {
var root = document.getElementsByTagName('body')[0];
var numberOfWatches = 0;
var f = function (element) {
var $element = angular.element(element);
var watchers = $element.scope().$$watchers;
if(watchers){
numberOfWatches += watchers.length;
}
angular.forEach($element.children(), function (childElement) {
f(childElement);
});
};
f(root);
return numberOfWatches;
};
console.log('Bindings: ', bindings);
console.log('Scopes: ', scopes);
console.log('Watchers (Body): ', watchers);
//console.log('Watchers (Entire page): ', getWatchers());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.