0

I'm developing a project on Angular5 and I always see that the providers of any service are declared on the ngModule section and I run out with the Augury debugger and checking the Injector Graph all the dependencies are coming from root.

There is any advantage to distribute the service providers by component? They will improve the quality of the app as building times or faster rendering?

Thanks in advance!

Nestor
  • 664
  • 11
  • 25
  • Explained here https://angular.io/guide/hierarchical-dependency-injection#scenario-service-isolation – Fetrarij Mar 29 '18 at 04:09

1 Answers1

0

If you add service into AppModule providers array, it tells to Angular to create a singleton, shared instance of Your Service and inject into any class that asks for it. Here is the reference

If you add service into Component providers array, it tells to Angular to create a instance only for that component, This instance won't be shared to other component. Here is the reference

So what your need? according to your necessity, You have to take a decision which is needed or not for you.

Thanks.

Shohel
  • 3,886
  • 4
  • 38
  • 75