Register a Service to Angular’s Dependency Injection Mechanism
Given that services are simple classes we could just import them in our component via normal ES2015 import statements and then instantiate them accordingly.
However, a service might depend upon other services as well and we definitely don’t want to manually wire up the entire chain of such dependencies. That’s why we have the dependency injector in Angular which will do it for us.
In this lesson we learn how to wire up our service properly by defining a provider that creates our service. We will also see how services defined on
NgModule are globally visible because they are hooked up onto Angular’s root injector.