Providers in Angular

Let's go through all the different approaches for creating providers in Angular.

What is the provider?

So, we’ve had a look at what Injectors are and the various levels of Injectors in Angular, but now we are going to have a look at providers. We have seen them briefly already, but it’s worth having a more in-depth look at them and the role they fulfill in Angular.

The Injector needs a provider to create the instances (versions) of the classes being injected into all the components, services, and directives.

The way this relationship between injector and provider is set up is through a token that the injector uses at runtime to create the required class that the provider needs. So, when our application is running and a class is needed via Dependency Injection, the token that the provider gives makes sure that the class being used is the one with the correct token.

Get hands-on with 1200+ tech skills courses.