In-depth Guides
Dependency Injection

Dependency injection in Angular

"DI" is a design pattern and mechanism for creating and delivering some parts of an app to other parts of an app that require them.

Tip: Check out Angular's Essentials before diving into this comprehensive guide.

When you develop a smaller part of your system, like a module or a class, you may need to use features from other classes. For example, you may need an HTTP service to make backend calls. Dependency Injection, or DI, is a design pattern and mechanism for creating and delivering some parts of an application to other parts of an application that require them. Angular supports this design pattern and you can use it in your applications to increase flexibility and modularity.

In Angular, dependencies are typically services, but they also can be values, such as strings or functions. An injector for an application (created automatically during bootstrap) instantiates dependencies when needed, using a configured provider of the service or value.

Learn about Angular dependency injection