Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // from: https://angularjs.de/artikel/angularjs-access-scope-via-console
- // bug fixed
- // fetch all elements with ng-scope class
- var scopeElements = Array.prototype.slice.apply(document.querySelectorAll(".ng-scope"));
- // map elements to scopes
- var scopes = scopeElements.map(function (element) {
- return angular.element(element).scope();
- });
- // filter duplicated scopes created by ng-view
- var scopesById = {};
- var uniqueScopes = [];
- scopes.forEach(function (scope) {
- if (scopesById[scope.$id] === undefined) {
- scopesById[scope.$id] = scope;
- uniqueScopes.push(scope);
- }
- });
- // map uniqueScopes to watchers
- var watchers = uniqueScopes.map(function (scope) {
- return scope.$$watchers;
- });
- // extract the length
- var watchersLengths = watchers.map(function (watcher) {
- return watchers.length;
- })
- // sum up the length with reduce
- var watchersCount = watchersLengths.reduce(function(a,b) {
- return a + b;
- });
- console.log("watchersCount: " + watchersCount);
Add Comment
Please, Sign In to add comment