Join egghead, unlock knowledge.

Want more egghead?

This lesson is for members. Join us? Get access to all 3,000+ tutorials + a community with expert developers around the world.

Unlock This Lesson
1×
Become a member
to unlock all features

Level Up!

Access all courses & lessons on egghead today and lock-in your price for life.

Autoplay

    Register a Service to Angular’s Dependency Injection Mechanism

    angularAngular
    5 - 7

    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.