Created
September 22, 2015 09:42
-
-
Save dhoko/cbd9a5c35d12740abeb4 to your computer and use it in GitHub Desktop.
[Bookmarklet] Debug AngularJS
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
// Version without jQuery | |
javascript:(function () { var root = angular.element(document.getElementsByTagName('body')); var watchers = []; var f = function (element) { angular.forEach(['$scope', '$isolateScope'], function (scopeProperty) { if (element.data() && element.data().hasOwnProperty(scopeProperty)) { angular.forEach(element.data()[scopeProperty].$$watchers, function (watcher) { watchers.push(watcher); }); } }); angular.forEach(element.children(), function (childElement) { f(angular.element(childElement)); }); }; f(root); var watchersWithoutDuplicates = []; angular.forEach(watchers, function(item) { if(watchersWithoutDuplicates.indexOf(item) < 0) { watchersWithoutDuplicates.push(item); } }); console.log(watchersWithoutDuplicates.length); })(); | |
// Version with jQuery | |
javascript:(function () { var root = $(document.getElementsByTagName('body')); var watchers = []; var f = function (element) { if (element.data().hasOwnProperty('$scope')) { angular.forEach(element.data().$scope.$$watchers, function (watcher) { watchers.push(watcher); }); } angular.forEach(element.children(), function (childElement) { f($(childElement)); }); }; f(root); console.log(watchers.length); })(); | |
/** | |
* Usage | |
* Click bookmarklet | |
* In da console view total | |
*/ |
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
// Get the current scope for dom item | |
javascript:scope=function(o){console.log(angular.element(o).scope()); return angular.element(o).scope()} | |
/** | |
* Usage | |
* clcik bookmarklet | |
* select item in the dom | |
* in da console do scope($0) ($0 or document.querySelector(<selector>)) |
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
// Inject any service from your app | |
javascript:inject = angular.element(document.body).injector().get | |
/** | |
* Usage | |
* Click bookmarklet | |
* In da console do var service = inject(<serviceName>); | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment