1

I have a Service which I would like to provide to 2 Lazy Modules - but not for the whole application.

I'm Providing the Service through a Module with the forRoot(): ModuleWithProviders convention into those 2 Lazy Modules - which leads to 2 Instances of the Service. If I would use forRoot in app.module I could use forChild in the lazy Modules but then the Service is loaded for the whole application.

Is it possible to only load the Service for Lazy Modules and still have it as a Singleton?

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
xanx2323
  • 11
  • 1
  • I think you need to follow the official docs, your case is to use provodedIn ‘root’ and import your service where applicable – KQI Aug 20 '21 at 21:16
  • but then the Service is loaded on start so there is no possible way for the service to be lazy? – xanx2323 Aug 22 '21 at 14:03

1 Answers1

0

Maybe you can create a tree of modules. Create a lazy module that contains the service and the other two lazy modules. Although I personally would put the service and leave it in a shared module.