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
This commit is contained in:
parent
01d1c46b16
commit
3783976543
@ -41,18 +41,6 @@ to import `FormsModule`, `SharedModule` can still export
|
|||||||
way, you can give other modules access to `FormsModule` without
|
way, you can give other modules access to `FormsModule` without
|
||||||
having to import it directly into the `@NgModule` decorator.
|
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
|
## More on NgModules
|
||||||
|
|
||||||
You may also be interested in the following:
|
You may also be interested in the following:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user