NG.IV · Angular 22 practice question

A developer has two components, Root and Child, where Child is rendered inside Root. If Child explicitly provides a specific instance of a service via its `@Component` decorator's `providers` array, what is the immediate effect when Child injects that same service?

/* Component Child */
@Component({
  selector: 'app-child',
  providers: [{provide: FlowerService, useValue: {emoji: '🌻'}}] 
})
export class Child {
  flower = inject(FlowerService);
}
Choose one answer
Check answer and explanation

Correct answer: The injector stops searching immediately upon finding the service in Child's local provider array, preventing traversal up the component tree.

Explanation

The injector halts its search as soon as it locates the required service within the Child's local provider array, thereby avoiding upward traversal through the component hierarchy.

Common trap

One description details standard dependency injection behavior without local overrides, while another assertion incorrectly claims the service will always use the root-level version, contradicting the hierarchical lookup principle when a local provider is present.

Source: Angular docs: Hierarchical injectors — Using the `providers` array
Checked against the cited text on 2026-11-25.

Report an error in this question