0

I want to inject a service created one module into a second totally different module, that depends on some data created by the first module. Let's say you import a feature module for authentication into your project and also a module to create a websocket. For authentication purpose you need an id saved in the local storage, that can be very easily accessed by the service from the authentication module, which has already been created. In the websocket module I provide an configuration in the forRoot method, so the socket endpoint can be defined, as well as the already created authentication service instance from the authentication module.

Now my question is: how can I get this service instance and how can I inject it into my configuration for the websocket module?

andreas.teich
  • 789
  • 1
  • 12
  • 22
  • The correct way to resolve your problem is it create the service in a **shared module** and pass its reference to the **app module** which can be used across multiple modules. – Aakash Chopra Mar 02 '20 at 12:05
  • Does this answer your question? [Angular2 Module: How can i import a service from another module](https://stackoverflow.com/questions/40396070/angular2-module-how-can-i-import-a-service-from-another-module) – Shravan Mar 02 '20 at 12:16
  • No, not really, let's say you have the following `app.module.ts` file: `LoginModule.forRoot({ settings: false }), DataProviderModule.forRoot( { serverUrl: '', loginService 'reference-to-service-instance-from-login-module} )` How could I achieve that? – andreas.teich Mar 02 '20 at 14:22

0 Answers0