Suggest an editImprove this articleRefine the answer for “What is Dependency Injection (DI) in Angular? Why is the DI mechanism needed?”. Your changes go to moderation before they’re published.Approval requiredContentWhat you’re changing🇺🇸EN🇺🇦UAPreviewTitle (EN)Short answer (EN)**Dependency Injection (DI)** is a mechanism Angular uses to automatically supply the needed dependencies (for example, services) to components, directives, or other classes, instead of creating objects manually with `new`. **Key point:** DI takes over creating and supplying objects, which keeps the code cleaner, more flexible, and easier to maintain.Shown above the full answer for quick recall.Answer (EN)Image**Dependency Injection (DI)** is a mechanism Angular uses to **automatically supply the needed dependencies** (for example, services) to components, directives, or other classes. ### In simple terms: Instead of creating objects manually with `new`, Angular **creates and supplies them itself** when they are needed. --- ### Example: ```ts import { Component } from '@angular/core'; import { UserService } from './user.service'; @Component({ selector: 'app-profile', template: `{{ userService.userName }}` }) export class ProfileComponent { constructor(public userService: UserService) {} } ``` Here `UserService` is automatically created by Angular and passed into the component's constructor. You do not need to write `new UserService()` - Angular already knows how to do it. --- ### Why DI is needed: 1. **Less coupling.** Components do not know *how* services are created, only *that they exist*. 2. **Easier to test.** Dependencies can be swapped for fakes (mocks). 3. **Reusability.** One service can be used in multiple places. 4. **Lifetime management.** Angular decides when to create and destroy dependencies. --- **Summary:** Dependency Injection is a way for Angular to take over creating and supplying the needed objects, so the code stays cleaner, more flexible, and easier to maintain.For the reviewerNote to the moderator (optional)Visible only to the moderator. Helps review go faster.