Dependency injection
Last modified on Mon 04 Jan 2021

Dependency Injection (DI) is utilized heavily in Angular, primarily for providing instances of either primitive values or class instances.

DI is a complex topic that requires a separate discussion which would be out of the scope of this handbook. We recommend checking out the following resources:

As of Angular 6, make sure to use { providedIn: 'root' } for singletons whenever possible.

DI is very useful for testing purposes, as shown in a later chapter.