Bird
0
0

You want to add logging features to an Angular app without changing existing services. How can the multi-provider pattern help?

hard📝 Application Q15 of 15
Angular - Advanced Patterns
You want to add logging features to an Angular app without changing existing services. How can the multi-provider pattern help?
ARegister multiple logging services under one token with multi: true, then inject all to run logs
BReplace existing services with new ones using the same token without multi: true
CCreate a new module that imports all services separately
DUse multi-provider pattern to inject only the first registered service
Step-by-Step Solution
Solution:
  1. Step 1: Understand the goal

    You want to add logging features without changing existing services, so you need to add providers without replacing them.
  2. Step 2: Apply multi-provider pattern

    Register multiple logging services under one token with multi: true. Angular injects all as an array, allowing combined logging without modifying existing code.
  3. Final Answer:

    Register multiple logging services under one token with multi: true, then inject all to run logs -> Option A
  4. Quick Check:

    Multi-provider adds features by injecting arrays of providers [OK]
Quick Trick: Use multi: true to add features without replacing services [OK]
Common Mistakes:
  • Replacing instead of adding providers
  • Not using multi: true and losing existing providers
  • Confusing multi-provider with module imports

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes