Angular service decorator providedIn root effect on lazy loading

Yes in this case it will be only part of your lazy-loaded module/chunks. When using providedIn: 'root' the Angular compiler will figure out the perfect way automatically:

  1. The service will be available application wide as a singleton with no need to add it to a module’s providers array (like Angular <= 5).
  2. If the service is only used within a lazy loaded module it will be lazy loaded with that module
  3. If it is never used it will not be contained in the build (tree shaked).

For further informations consider reading the documentation and NgModule FAQs

Btw:

  1. If you don’t want a application-wide singleton use the provider’s array of a component instead.
  2. If you want to limit the scope so no other developer will ever use your service outside of a particular module, use the provider’s array of NgModule instead.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)