Calling angular services globally

Ivan

I have a set of services which represent a backend logic, that is called by different angular controllers.

During development however I want to call these services directly, in order to test them in isolation, from the browser Javascript console. How this can be done?

Say there is

app.service('service1', function() {
    this.sayHello = function() {
        return "Hello"
    };
});

Now from Javascript console,

app.somethingToGetService('service1').sayHello()

?

Yuriy Rozhovetskiy

You can get injector for module and from it get service:

angular.injector(['ng', 'myApp']).get('service1').sayHello()

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Are Angular services available globally?

From Dev

Globally toggle between the use of mocked services in Angular 2

From Dev

CORS - Calling rest services on Tomcat from angular

From Dev

Problems setting up mock services and calling it with jasmine/ karma and Angular

From Dev

Problems setting up mock services and calling it with jasmine/ karma and Angular

From Dev

Globally register a directive in Angular

From Dev

Globally configuring Angular directives

From Dev

Globally available variables with Angular

From Dev

Calling RestFul Services

From Dev

Calling RestFul Services

From Dev

Calling Services in a custom directive

From Dev

Setting Angular $resource Config Globally

From Dev

How do you make AngularJS built-in services available globally?

From Dev

Accessing root Angular 2 injector instance globally

From Java

Handling 401s globally with Angular

From Dev

Set angular.js url root globally

From Dev

How to configure Angular UI bootstrap directives globally

From Dev

Expose current logged in user globally in Angular and Firebase

From Dev

Display http errors globally with Angular 2

From Dev

Display http errors globally with Angular 2

From Dev

angular-cli globally installation failure

From Dev

Injection of Generic Services in Angular

From Dev

Why are angular services Singletons?

From Dev

Angular 2 - Singleton Services?

From Dev

Angular seed with services and directives

From Dev

Angular Services/Factories with $resource

From Dev

Nested Services in Angular 2

From Dev

Angular.js Services

From Dev

Is there a way to group services in angular?