INTERVIEW QUESTIONS

Angular Interview Questions

Practice Angular prompts by theme and build clearer interview answers.

Practice by topicAngular topic lensesClear answer prompts

Showing 6 Dependency Injection practice prompts

A

ANGULAR

What is Dependency Injection (DI) in Angular?

Dependency Injection is a design pattern where Angular instantiates and provides dependencies (such as services) to components or other services rather than having them create them directly. Dependencies are declared via constructor parameters or modern `inject(ServiceToken)` calls, managed by Angular's hierarchical injector tree.
◦ dependency injection
A

ANGULAR

What is the purpose of an Angular Service?

Services encapsulate reusable business logic, external API communication (via `HttpClient`), state caching, and utility functions outside of the UI layer. They are annotated with `@Injectable({ providedIn: 'root' })` to provide singleton instances accessible across the application.
◦ dependency injection
A

ANGULAR

What is the purpose of `providedIn: 'root'` in `@Injectable`?

`providedIn: 'root'` registers the service with the application's root injector, creating a single application-wide singleton instance. Crucially, it enables build-time tree-shaking: if the service is never injected anywhere in code, the bundler removes it from the final production JavaScript bundle.
◦ dependency injection
A

ANGULAR

How does Hierarchical Dependency Injection work in Angular?

Angular's injectors form a tree corresponding to the DOM and module hierarchy. When a component requests a dependency, Angular checks the element's local injector, then walks up parent component injectors, then environment/root injectors. If a child component declares a service in its own `providers: [MyService]`, it receives an isolated instance without affecting sibling or parent instances.
◦ dependency injection
A

ANGULAR

What is the purpose of `InjectionToken` in Angular?

`InjectionToken` is used to inject non-class dependencies (such as configuration objects, primitive strings, environment variables, or interfaces that do not exist at JavaScript runtime). For example: `export const API_URL = new InjectionToken<string>('api.url');` provided via `{ provide: API_URL, useValue: 'https://api.com' }` and consumed via `inject(API_URL)`.
◦ dependency injection

Your next interview is closer than you think.

Practice smarter and land better opportunities.

✓ Start with the free plan✓ No credit card✓ Cancel anytime
Start preparing free