I have created few services in angular with provideIn as root using the following code.
@Injectable({
providedIn: 'root'
}
This makes the service available to the whole application and I can import it anywhere I like. This seems very easy to do and is very intuative. But I was reading angular docs and came across Angular Dependency providers. I understand the concept behind it is to expose the service only to those components that need it. But I don't understand whats the use of this? We can make service available at root level and access where ever needed. Are there any optimisations benefit of configuring depenceny providers or is it merely because of security reasons or for any other reason?
Aucun commentaire:
Enregistrer un commentaire