Use "providedIn" service registration to avoid multiple instances with lazy loaded modules

Share this video with your friends

Send Tweet

Angular's DI is quite powerful. There are however some peculiarities when it comes to the registration of Angular services with the dependency injector, in combination with lazy loaded Angular modules. The way you register the Angular service (e.g. using the providers array on a NgModule or the providedIn decorator) might have a direct impact on the instances of the service you have in memory at runtime. Let's explore that in more detail.

You can also read more details in my blog post