Skip to content

Instantly share code, notes, and snippets.

@levriero
Created November 10, 2014 16:41
Show Gist options
  • Select an option

  • Save levriero/2ada71ff8af58731291e to your computer and use it in GitHub Desktop.

Select an option

Save levriero/2ada71ff8af58731291e to your computer and use it in GitHub Desktop.
Count the number of bindings in your angular app
// Requieres lodash or underscore
function getScopes(root) {
var scopes = [];
function traverse(scope) {
scopes.push(scope);
if (scope.$$nextSibling) {
traverse(scope.$$nextSibling);
}
if (scope.$$childHead)
traverse(scope.$$childHead);
}
traverse(root);
return scopes;
}
var rootScope = angular.element(document.querySelectorAll("[ng-app]")).scope();
var scopes = getScopes(rootScope);
var watcherLists = scopes.map(function(s) { return s.$$watchers; });
_.uniq(_.flatten(watcherLists)).length;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment