NG.IV · Angular 22 practice question

A service needs to utilize multiple distinct authorization handlers, each registered under the same injection token. To ensure the service receives an array containing all registered handlers, what must be true about the provider configuration for each handler?

providers: [
  {provide: AuthToken, useClass: HandlerA, multi: true},
  {provide: AuthToken, useClass: HandlerB, multi: true}
]
Choose one answer
Check answer and explanation

Correct answer: The token must be defined as an InjectionToken, and each provider must include the 'multi: true' flag.

Explanation

The proper setup mandates declaring the token and ensuring that every provider supplying that token includes the 'multi: true' attribute, leading to the injection of an array.

Common trap

The suggestion that providers must be listed in order, allowing the injection mechanism to automatically combine them, is flawed because Angular necessitates the explicit 'multi: true' flag to gather multiple instances under a single token.

Source: Angular docs: Defining dependency providers — Multiple providers
Checked against the cited text on 2026-11-25.

Report an error in this question