admin管理员组文章数量:1136511
Is there a way of debugging the angularjs application when it is loaded in the browser?
ie. I wish to get the $rootScope
of my current application. How would I do that?
Is there a way of debugging the angularjs application when it is loaded in the browser?
ie. I wish to get the $rootScope
of my current application. How would I do that?
7 Answers
Reset to default 81+1 for Batarang
Also, you can get the scope from any element in the DOM by executing the following from the console
angular.element(DOMNODE).scope()
Where DOMNODE, is of course, a reference to a DOM node.
For example, in Chrome in the elements tab you can select the node where the ng-app
directive is, and get the root scope with
angular.element($0).scope()
In the developer console try this
$rootScope = angular.element(document).scope()
Batarang -- A Google Chrome plugin for AngularJS
After you installed this, you can do
console.log($rootScope);
and check the scope object in your chrome console.
BTW, if you want to get $rootScope, you need to inject to your controller
like
app.controller('MainCtrl', function($scope, $rootScope) {
}
In developer console type angular.element('body').scope();
in case of your app is <body data-ng-app="SomeApp">
For those using $compileProvider.debugInfoEnabled(false);
and ng-strict-di
just paste this in the console and $rootScope
will be logged and added to window
:
function getRootScope($rootScope){ console.log(window.$rootScope = $rootScope); }
getRootScope.$inject = ["$rootScope"];
angular.element(document.querySelector('[data-ng-app],[ng-app]')).injector().invoke(getRootScope);
You can see the $rootScope in your sources Developer Tools->Sources
Just wanted to add that there is a free Chrome Extension called "Angular Scope Inspector" (current store url) that will automatically inspect scope of selected elements in the developer tools elements tab
I just discovered it today, and it's very useful, IMO
本文标签: javascripthow to debug the rootScope object of angularjs in the browserStack Overflow
版权声明:本文标题:javascript - how to debug the $rootScope object of angularjs in the browser - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736942975a1957175.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论