Dependency Injection
noun
say it: “dih-PEN-den-see in-JEK-shun” /dɪˈpɛndənsi ɪnˈdʒɛkʃən/
Angular's system for creating services and handing them to the classes that ask for them.
What is Dependency Injection?
Dependency injection is how Angular hands components and services the other services they need. You ask for a CartService, and Angular creates one (or reuses the existing one) and gives it to you.
export class CartPage {
private cart = inject(CartService); // Angular supplies it
}
In a sentence
- “Through dependency injection, every component asking for Cart gets the same instance.”
Level: Apprentice · More Angular terms at this level
Updated