@ -10,7 +10,7 @@ see the <live-example></live-example>.
|
||||
<hr>
|
||||
|
||||
## Create a service
|
||||
You can provide services to your app by using the providers array in an NgModule.
|
||||
You can provide services to your app by using the `providers` array in an NgModule.
|
||||
Consider the default app generated by the CLI. In order to add a user service to it,
|
||||
you can generate one by entering the following command in the terminal window:
|
||||
|
||||
@ -20,7 +20,7 @@ ng generate service User
|
||||
|
||||
This creates a service called `UserService`. You now need to make the service available in your
|
||||
app's injector. Update `app.module.ts` by importing it with your other import statements at the top
|
||||
of the file and adding it to the providers array:
|
||||
of the file and adding it to the `providers` array:
|
||||
|
||||
<code-example path="providers/src/app/app.module.ts" title="src/app/app.module.ts" linenums="false">
|
||||
</code-example>
|
||||
@ -28,7 +28,7 @@ of the file and adding it to the providers array:
|
||||
|
||||
## Provider scope
|
||||
|
||||
When you add a service provider to the providers array of the root module, it’s available throughout the app. Additionally, when you import a module that has providers, those providers are also available to all the classes in the app as long they have the lookup token. For example, if you import the `HttpClientModule` into your `AppModule`, its providers are then available to the entire app and you can make HTTP requests from anywhere in your app.
|
||||
When you add a service provider to the `providers` array of the root module, it’s available throughout the app. Additionally, when you import a module that has providers, those providers are also available to all the classes in the app as long they have the lookup token. For example, if you import the `HttpClientModule` into your `AppModule`, its providers are then available to the entire app and you can make HTTP requests from anywhere in your app.
|
||||
|
||||
|
||||
## Limiting provider scope by lazy loading modules
|
||||
|
Reference in New Issue
Block a user