如何在浏览器中调试 Angular 服务 [英] how to debug angular services in browser
本文介绍了如何在浏览器中调试 Angular 服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在我的 angular 应用程序中创建了一个工厂/服务.
I have created a factory/service in my angular app.
我想在浏览器中调试它.有没有办法可以访问它的实例并检查它的函数和变量的值是多少.
I want to debug it in the browser. Is there a way that I can access its instance and check what is the value of its functions and variables.
可以使用
angular.element(e).scope()
有没有类似的方法来访问工厂?
Is there a similar way to access factories ?
推荐答案
我相信你可以这样使用:
I believe you can use something like this:
angular.element(e).injector().get('serviceName')
并且由于 angularjs 服务是单例,因此在任何 angular.element 上执行此操作将始终返回相同的服务实例/对象.
And since angularjs services are singletons, doing this on any angular.element will always return the same service instance/object.
这篇关于如何在浏览器中调试 Angular 服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文