If I want to use service across the whole app, I should declare it as provider in app.module.ts
, but it also works if it is declared in app.component.ts
.
Is there any significant difference in those two approaches?
Let's say you have three components that are declared in your AppModule
. If you provide service individually in every component, each of them will have its own instance of service, but if you provide it in AppModule
, your service will be singleton - each component will share one same instance of that service.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With