Skip to content

Commit f0cfd37

Browse files
committed
Add providers questions
1 parent 955cc88 commit f0cfd37

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

Diff for: README.md

+22-8
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,8 @@
237237
|229| [What are the steps to use declaration elements?](#what-are-the-steps-to-use-declaration-elements)|
238238
|230| [What happens if browserModule used in feature module?](#what-happens-if-browsermodule-used-in-feature-module)|
239239
|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#)|
242242
|234| [?](#)|
243243
|235| [?](#)|
244244
|236| [?](#)|
@@ -3404,15 +3404,25 @@
34043404
34053405
**[⬆ Back to Top](#table-of-contents)**
34063406
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';
34123415
3416+
@Injectable({
3417+
providedIn: 'root', //Angular provide the service in root injector
3418+
})
3419+
export class MyService {
3420+
}
3421+
```
34133422
**[⬆ Back to Top](#table-of-contents)**
34143423
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.
34163426
34173427
**[⬆ Back to Top](#table-of-contents)**
34183428
@@ -3482,4 +3492,8 @@
34823492
34833493
250. ### ?
34843494
3495+
**[⬆ Back to Top](#table-of-contents)**
3496+
3497+
251. ### ?
3498+
34853499
**[⬆ Back to Top](#table-of-contents)**

0 commit comments

Comments
 (0)