Dependency injection

Dependency injection is a mechanism where a class receives the objects it needs instead of creating them itself. Angular supplies an instance through an injector; you request it with the inject() function or the constructor. It makes reuse easier and replacement with test doubles possible.

Example

private http = inject(HttpClient);

Related concepts

The whole glossary