Bird
0
0

Which of the following is a correct way to declare a multi-provider in Angular?

easy📝 Conceptual Q2 of 15
Angular - Advanced Patterns
Which of the following is a correct way to declare a multi-provider in Angular?
A{ provide: 'MY_TOKEN', useValue: 'value1', multi: true }
B{ provide: 'MY_TOKEN', useClass: MyClass }
C{ provide: 'MY_TOKEN', useValue: 'value1' }
D{ provide: 'MY_TOKEN', useFactory: () => 'value1' }
Step-by-Step Solution
Solution:
  1. Step 1: Identify multi-provider syntax

    Multi-provider requires the property multi: true to allow multiple providers for the same token.
  2. Step 2: Check each option for multi: true

    Only { provide: 'MY_TOKEN', useValue: 'value1', multi: true } includes multi: true, making it a valid multi-provider declaration.
  3. Final Answer:

    { provide: 'MY_TOKEN', useValue: 'value1', multi: true } -> Option A
  4. Quick Check:

    Multi-provider syntax includes multi: true [OK]
Quick Trick: Always add multi: true for multi-provider declarations [OK]
Common Mistakes:
  • Omitting multi: true when registering multiple providers
  • Using useClass without multi: true for multi-provider
  • Confusing single provider syntax with multi-provider

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes