Bird
0
0

Given this Angular provider setup:

medium📝 state output Q13 of 15
Angular - Advanced Patterns
Given this Angular provider setup:
providers: [
  { provide: 'TOKEN', useValue: 'A', multi: true },
  { provide: 'TOKEN', useValue: 'B', multi: true }
]

What will Angular inject when you ask for inject('TOKEN')?
AAn array ['A', 'B']
BThe string 'B'
CAn array ['B', 'A']
DAn error because of duplicate tokens
Step-by-Step Solution
Solution:
  1. Step 1: Understand multi-provider injection behavior

    When multiple providers use the same token with multi: true, Angular injects an array of all values in registration order.
  2. Step 2: Analyze given providers

    Providers register 'A' first, then 'B'. So injection returns ['A', 'B'].
  3. Final Answer:

    An array ['A', 'B'] -> Option A
  4. Quick Check:

    Multi-provider injects array of all registered values [OK]
Quick Trick: Multi-provider injects array in registration order [OK]
Common Mistakes:
  • Assuming only last provider is injected
  • Thinking order is reversed
  • Expecting a single value instead of array

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes