Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to debug angular services in browser

Tags:

angularjs

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.

The angular scope can be accessed using

angular.element(e).scope() 

Is there a similar way to access factories ?

like image 846
murtaza52 Avatar asked Jan 11 '13 12:01

murtaza52


People also ask

Can we debug Angular code in browser?

The Console With the Chrome DevTools console, you can execute custom code and display your application logs. By running custom JavaScript code, you can debug your Angular app. For example, using console.


1 Answers

I believe you can use something like this:

angular.element(e).injector().get('serviceName') 

And since angularjs services are singletons, doing this on any angular.element will always return the same service instance/object.

like image 147
bmleite Avatar answered Oct 27 '22 00:10

bmleite