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:

  • Using Angular DI tokens
  • Optional dependencies
  • Creating a singleton service using providedIn
  • Creating a singleton service using forRoot()
  • Providing alternate classes against the same DI token
  • Dynamic configurations using value ...

Get Angular Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.