You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+22-8
Original file line number
Diff line number
Diff line change
@@ -237,8 +237,8 @@
237
237
|229|[What are the steps to use declaration elements?](#what-are-the-steps-to-use-declaration-elements)|
238
238
|230|[What happens if browserModule used in feature module?](#what-happens-if-browsermodule-used-in-feature-module)|
239
239
|231|[What are the types of feature modules?](#what-are-the-types-of-feature-modules)|
240
-
|232|[?](#)|
241
-
|233|[?](#)|
240
+
|232|[What is a provider?](#what-is-a-provider)|
241
+
|233|[What is the recommendation for provider scope?](#what-is-the-recommendation-for-provider-scope#)|
242
242
|234|[?](#)|
243
243
|235|[?](#)|
244
244
|236|[?](#)|
@@ -3404,15 +3404,25 @@
3404
3404
3405
3405
**[⬆ Back to Top](#table-of-contents)**
3406
3406
3407
-
231. ### ?
3408
-
3409
-
**[⬆ Back to Top](#table-of-contents)**
3410
-
3411
-
232. ### ?
3407
+
232. ### What is a provider?
3408
+
A provider is an instruction to the Dependency Injection system on how to obtain a value for a dependency(aka services created). The service can be provided using Angular CLI as below,
3409
+
```javascript
3410
+
ng generate service my-service
3411
+
```
3412
+
The created service by CLI would be as below,
3413
+
```js
3414
+
import { Injectable } from '@angular/core';
3412
3415
3416
+
@Injectable({
3417
+
providedIn: 'root', //Angular provide the service in root injector
3418
+
})
3419
+
export class MyService {
3420
+
}
3421
+
```
3413
3422
**[⬆ Back to Top](#table-of-contents)**
3414
3423
3415
-
233. ### ?
3424
+
233. ### What is the recommendation for provider scope?
3425
+
You should always provide your service in the root injector unless there is a case where you want the service to be available only if you import a particular @NgModule.
0 commit comments