When should we use providedIn root vs module for services

0 votes
I was hoping you could explain to me with the help of an example. When should we use the ‘root’ vs ‘module’ for services?
6 days ago in Angular by Nidhi
• 10,860 points
28 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

In Angular, the providedIn property in the @Injectable() decorator determines where a service is provided.

Use providedIn: 'root'

Example:

@Injectable({

  providedIn: 'root'

})

export class MyService { }

Use providedIn: 'module'

@NgModule({

  providers: [MyService]

})

export class MyModule { }

answered 6 days ago by Tanya

edited 3 days ago

Related Questions In Angular

0 votes
1 answer

Should I use map or switchmap when using angular http module?

When working with the Angular HTTP module, ...READ MORE

answered Feb 24 in Angular by Navya
44 views
0 votes
0 answers

When to use switchMap vs concatMap?

With the help of an example, can ...READ MORE

6 days ago in Angular by Nidhi
• 10,860 points
52 views
0 votes
1 answer

Which module is used for routing in AngularJs?

The ngRoute module helps your application to become a ...READ MORE

answered Feb 4, 2020 in Angular by Niroj
• 82,840 points
1,425 views
0 votes
1 answer

How can we display message when we click some element(button) that server is loading?

hey kartik,  As $route is used for deep-linking URLs ...READ MORE

answered Feb 11, 2020 in Angular by Niroj
• 82,840 points
4,385 views
0 votes
0 answers

How to use Angular services to share data between components?

Explain me with the help of an ...READ MORE

6 days ago in Angular by Nidhi
• 10,860 points
23 views
0 votes
0 answers

Can we use async pipe instead of manually subscribing?

With the help of an example, can ...READ MORE

4 days ago in Angular by Nidhi
• 10,860 points
18 views
0 votes
1 answer

How to know tools and bundlers after create a new workspace or a project in angular?

Hello @sajal, When you create projects and workspaces ...READ MORE

answered Aug 6, 2020 in Angular by Niroj
• 82,840 points
1,138 views
0 votes
0 answers

How do you diagnose an injector fault?

Explain me with the help of an ...READ MORE

6 days ago in Java-Script by Nidhi
• 10,860 points
25 views
0 votes
0 answers

How to pass data from one service to another service in Angular?

Explain me with the help of an ...READ MORE

6 days ago in Angular by Nidhi
• 10,860 points
21 views
0 votes
0 answers

How do Observables improve API call handling in Angular?

With the help of an example, can ...READ MORE

6 days ago in Angular by Nidhi
• 10,860 points
41 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP