Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Get service instance from the "global" scope #595

@lukaszdechovan

Description

@lukaszdechovan

Hello,

If I inject angular service into a controller, the angular creates new instance and put it into instanceCache object... so there is only one instance of the service even if I use more controllers (it's a singleton).

However, I would like to get that one instance from instanceCache outside the controller.
I know there is a possibility how to achieve this within new angular.scope()....

var scope = angular.scope();
var myService = scope.$service('Id of myService under which it was registered'); 

.... but this code creates new instance of myService so if I inject myService also into controller, now I have 2 separate instances in the application.

Is there any way how can I achieve this with angular.js?
I tried also angular.element('selector to whatever').scope() is always undefined.... I hoped I can access the scope of the controller and get service from that scope.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions