0

Is it possible to get an angular js service into the global scope to use in the JS Debugging console? What I'm going for is some very low tech, quick and dirty, testing. Something like:

var myService = angular.injector().get('myService');
myService.doSomething();

and have it do something.

But I keep getting

Error: Unknown provider: myServiceProvider <- myService

1 Answer 1

6

In your console you can do something like this:

var domElement = document.getElementById('elementInApp');//
var el = angular.element(dom);
var myService = el.get('myService');
myService.doSomething();

This will allow you to use the existing application injector instead of creating a new (which is basically what you are doing).

//you can also do this
var newMyService = angular.injector(['moduleWithMyService']).get('myService');
//note that this creates a new 'myService' so
newMyService === myService; //false
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.