Chapter 3: The Magic of Dependency Injection in Angular
This chapter is all about the magic of dependency injection (DI) in Angular. Here, you'll learn some detailed information about the concept of DI in Angular. DI is the process that Angular uses to inject different dependencies into components, directives, and services. You'll work with several examples using services and providers to get some hands-on experience that you can utilize in your later Angular projects.
In this chapter, we're going to cover the following recipes:
- Configuring an injector with a DI token
- Optional dependencies
- Creating a singleton service using
providedIn
- Creating a singleton service using
forRoot()
- Providing different services to the app with the same Aliased class provider
- Value providers in Angular