Skip to content

Instantly share code, notes, and snippets.

@strika
Created November 12, 2014 11:40
Show Gist options
  • Save strika/c39d1e2c79ca9505322d to your computer and use it in GitHub Desktop.
Save strika/c39d1e2c79ca9505322d to your computer and use it in GitHub Desktop.
Number of bindings in AngularJS application
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