I would like to refer the providedIn
option to an Angular module providing both declarables and dependencies. I created an additional module SharedModule
to serve as a sub-module of the lazy module LazyModule
so that it may be used as an “anchor” for the lazy service I want to provide (CounterService
in my case). I've been following this guide to achieve it but obviously doing something wrong.
Also, I made a little scheme but please take a look at the StackBlitz to see the full example.
Eager Part Lazy Loaded Module
+----------------------------------------------+ +--------------------------------------+
|Routes: | | @NgModule({ |
| | | imports: [SharedModule] |
|{ | | } |
| path: 'lazy', | | export class LazyModule {} |
| loadChildren: './lazy/lazy.module#LazyModule| | |
|} | | |
+----------------------------------------------+ | SharedModule |
| +----------------------------------+ |
| |@NgModule({ | |
| | declarations: [SharedComponent],| |
| | exports: [SharedComponent] | |
| |}) | |
| |export class SharedModule {} | |
| +----------------------------------+ |
| |
| |
| LazyService |
| +----------------------------------+ |
| |@Injectable({ | |
| | providedIn: SharedModule | |
| |}) | |
| |export class CounterService { | |
| | counter = 0; | |
| |} | |
| +----------------------------------+ |
| |
+--------------------------------------+