Avoid Multiple Service Instances in Lazy Loaded Modules in Angular
lessonDuration 5m 6s
Shared Angular modules may export components as well as services which are meant to be reused across the entire application. Whenever you want to use an exported component, in another module, you need to import the module defining that component accordingly. Services on the other hand are globally registered, there is one instance per dependency injector. However, there is something you should be aware of: **Lazy loaded modules have their own dependency injector.** As a result, importing shared modules in a lazy loaded module, may result in multiple instances of a service being available in the app. In this lesson we will learn about the `ModuleWithProviders` interface that helps avoid such situations.