diff --git a/aio/content/guide/ngmodule-faq.md b/aio/content/guide/ngmodule-faq.md index 27e0a78de2..980a75a670 100644 --- a/aio/content/guide/ngmodule-faq.md +++ b/aio/content/guide/ngmodule-faq.md @@ -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. - +
@@ -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. @@ -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. +
{@a q-lazy-loaded-module-provider-visibility} @@ -288,6 +289,7 @@ The `AppModule` always wins.
+{@a service-scope} ## How do I restrict service scope to a module? @@ -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 ``. 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. +
{@a q-root-component-or-module}