From 4e3fc7eac8828cbdeeac52aca6d6bae9879b0c26 Mon Sep 17 00:00:00 2001 From: 4javier <4javiereg4@gmail.com> Date: Tue, 9 Aug 2022 16:10:26 +0200 Subject: [PATCH] docs: clarify providers' injection in lazy loaded modules (#47094) Addresses https://github.com/angular/angular/issues/47059 I try to keep the edit as concise as possible because adding any further explanation would bring to much deeper info compared to the topic of the page Removed some convoluted info and replaced with a link to a page that should focus on the specific aspect of the matter. Conditional is obliged because IMHO that page should have a dedicated paragraph explaining various ways of populating different injectors with providers, and maybe integrating the interesting parts from the recent created page about standalone app. PR Close #47094 --- aio/content/guide/providers.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/aio/content/guide/providers.md b/aio/content/guide/providers.md index 651c97f658f..53713df7f70 100644 --- a/aio/content/guide/providers.md +++ b/aio/content/guide/providers.md @@ -63,11 +63,11 @@ This means that any services listed in their provider arrays aren't available be When the Angular router lazy-loads a module, it creates a new injector. This injector is a child of the root application injector. Imagine a tree of injectors; there is a single root injector and then a child injector for each lazy loaded module. -The router adds all of the providers from the root injector to the child injector. -When the router creates a component within the lazy-loaded context, Angular prefers service instances created from these providers to the service instances of the application root injector. +This child injector gets populated with all the module-specific providers, if any. +Look up resolution for every provider follows the [rules of dependency injection hierarchy](guide/hierarchical-dependency-injection#resolution-rules). -Any component created within a lazy loaded module's context, such as by router navigation, gets the local instance of the service, not the instance in the root application injector. -Components in external modules continue to receive the instance created for the application root. +Any component created within a lazy loaded module's context, such as by router navigation, gets its own local instance of child provided services, not the instance in the root application injector. +Components in external modules continue to receive the instances created for the application root injector. Though you can provide services by lazy loading modules, not all services can be lazy loaded. For instance, some modules only work in the root module, such as the Router.