Bird
0
0

Consider this Angular provider configuration:

medium📝 Predict Output Q5 of 15
Angular - Advanced Patterns
Consider this Angular provider configuration:
providers: [
  { provide: 'SERVICES', useClass: ServiceA, multi: true },
  { provide: 'SERVICES', useClass: ServiceB, multi: true }
]

What will be injected when 'SERVICES' is requested?
AOnly an instance of ServiceA
BAn array of ServiceA and ServiceB instances
COnly an instance of ServiceB
DA runtime error due to conflicting providers
Step-by-Step Solution
Solution:
  1. Step 1: Understand multi-provider with useClass

    Multi-provider with useClass creates instances of each class and injects them as an array.
  2. Step 2: Apply to given providers

    Both ServiceA and ServiceB are provided with multi: true, so injection returns an array of their instances.
  3. Final Answer:

    An array of ServiceA and ServiceB instances -> Option B
  4. Quick Check:

    Multi-provider with useClass injects array of instances [OK]
Quick Trick: Multi-provider with useClass injects array of instances [OK]
Common Mistakes:
  • Expecting only one instance instead of array
  • Assuming runtime error on multiple useClass providers
  • Confusing multi-provider with single provider behavior

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes