From 378397654390097c597cd5a2b11b9d2de750464c Mon Sep 17 00:00:00 2001 From: Amadou Sall Date: Tue, 27 Apr 2021 12:27:34 +0200 Subject: [PATCH] docs: remove the section "Using components vs services from other modules" (#41835) This section states that "Importing a module with services means that you will have a new instance of that service". This is only true for lazy-loaded `NgModules`. For non-lazy-loaded modules, my understanding is that the providers arrays are flattened into the root injector meaning that importing a module with a service doesn't create a new instance of that service. PR Close #41835 --- aio/content/guide/sharing-ngmodules.md | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/aio/content/guide/sharing-ngmodules.md b/aio/content/guide/sharing-ngmodules.md index 5bbbbbe987..85c5934b6c 100644 --- a/aio/content/guide/sharing-ngmodules.md +++ b/aio/content/guide/sharing-ngmodules.md @@ -41,18 +41,6 @@ to import `FormsModule`, `SharedModule` can still export way, you can give other modules access to `FormsModule` without having to import it directly into the `@NgModule` decorator. -### Using components vs services from other modules - -There is an important distinction between using another module's component and -using a service from another module. Import modules when you want to use -directives, pipes, and components. Importing a module with services means that you will have a new instance of that service, which typically is not what you need (typically one wants to reuse an existing service). Use module imports to control service instantiation. - -The most common way to get a hold of shared services is through Angular -[dependency injection](guide/dependency-injection), rather than through the module system (importing a module will result in a new service instance, which is not a typical usage). - -To read about sharing services, see [Providers](guide/providers). - - ## More on NgModules You may also be interested in the following: