Multi Providers in Angular2

112 views
Skip to first unread message

Tanu Pawar

unread,
Nov 14, 2017, 4:56:25 AM11/14/17
to Angular and AngularJS discussion

Hi,

I have a question related to multi providers in angular2, i intend to use it in my project. 

Suppose i have 3 modules , Root Module and two lazily loaded modules A and B. I have created token at root level. 
I provide the respective classes in child modules as below :
For module A
 { provide: IServiceToken, useClass: AService}

For module B
 { provide: IServiceToken, useClass: BService}

This approach works fine.

However , what if i want to access methods from both AService and BService in Root, 
i have written below code in root module

    providers: [
      
      { provide: IServiceToken, useClass: AService, multi: true },
      { provide: IServiceToken, useClass: BService, multi: true },
    ]
The above doesnt seem to work, gives error Mixing multi and non multi provider is not possible for token.

Is anything wrong with aproach, or can any one tell me possible way of achieving it?

Thanks,
Tanu

Sander Elias

unread,
Nov 14, 2017, 5:03:15 AM11/14/17
to Angular and AngularJS discussion
Hi Tanu,

I think Alex talked about this at AngularConnect. Check out his talk
If that's not covering your needs, please ask again, and I will look into it

Regards
Sander

Tanu Pawar

unread,
Nov 16, 2017, 4:11:40 AM11/16/17
to Angular and AngularJS discussion
Thankyou Sander, Link was helpful.


Regards,
Tanu 
Reply all
Reply to author
Forward
0 new messages