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
Understanding dependency injection
Learn basic principles of dependency injection in Angular.
Creating and injecting service
Describes how to create a service and inject it in other services and components.
Configuring dependency providers
Describes how to configure dependencies using the providers field on the @Component and @NgModule decorators. Also describes how to use InjectionToken to provide and inject values in DI, which can be helpful when you want to use a value other than classes as dependencies.
Injection context
Describes what an injection context is and how to use the DI system where you need it.
Hierarchical injectors
Hierarchical DI enables you to share dependencies between different parts of the application only when and if you need to. This is an advanced topic.