Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions aio/content/guide/ngmodule-faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ configure services in root and feature modules respectively.

Angular doesn't recognize these names but Angular developers do.
Follow this convention when you write similar modules with configurable service providers.
<!--KW--I don't understand how Angular doesn't understand these methods...-->


<hr/>

Expand All @@ -233,9 +233,8 @@ When you import an NgModule,
Angular adds the module's service providers (the contents of its `providers` list)
to the application root injector.

This makes the provider visible to every class in the application that knows the provider's lookup token, or knows its name.
This makes the provider visible to every class in the application that knows the provider's lookup token, or name.

This is by design.
Extensibility through NgModule imports is a primary goal of the NgModule system.
Merging NgModule providers into the application injector
makes it easy for a module library to enrich the entire application with new services.
Expand All @@ -247,6 +246,8 @@ If the `HeroModule` provides the `HeroService` and the root `AppModule` imports
any class that knows the `HeroService` _type_ can inject that service,
not just the classes declared in the `HeroModule`.

To limit access to a service, consider lazy loading the NgModule that provides that service. See [How do I restrict service scope to a module?](guide/ngmodule-faq#service-scope) for more information.

<hr/>

{@a q-lazy-loaded-module-provider-visibility}
Expand Down Expand Up @@ -288,6 +289,7 @@ The `AppModule` always wins.

<hr/>

{@a service-scope}

## How do I restrict service scope to a module?

Expand Down Expand Up @@ -335,6 +337,8 @@ You can embed the child components in the top component's template.
Alternatively, make the top component a routing host by giving it a `<router-outlet>`.
Define child routes and let the router load module components into that outlet.

Though you can limit access to a service by providing it in a lazy loaded module or providing it in a component, providing services in a component can lead to multiple instances of those services. Thus, the lazy loading is preferable.

<hr/>

{@a q-root-component-or-module}
Expand Down