Total Guide To Angular 6+ Dependency Injection

Total Guide To Angular 6+ Dependency Injection

In this case, the service is not a singleton and we get a new instance of the provided service every time we use component in the template of another component. It also means that the service instance will be destroyed together with the component…

The RandomService is registered in the providers: [] of the RandomComponent so we will get different random number every time we use component in our template.

[…]

Follow me on Twitter to get notified about the newest Angular blog posts and interesting frontend stuff!🐤

With the advent of Angular 6 we got this new shiny tool for modeling the dependencies in our applications. The official name is “Tree-shakable providers” and we use it by employing new providedIn property of the @Injectable decorator.

[…]