Bird
0
0

Why might you choose providedIn: 'any' over providedIn: 'root' for a service?

hard🧠 Conceptual Q10 of 15
Angular - Services and Dependency Injection
Why might you choose providedIn: 'any' over providedIn: 'root' for a service?
ATo disable dependency injection for the service.
BTo make the service available only in the root injector.
CTo get a new instance of the service in each lazy-loaded module.
DTo share the same instance across all modules.
Step-by-Step Solution
Solution:
  1. Step 1: Understand difference between 'any' and 'root'

    'root' provides a singleton instance app-wide; 'any' creates new instances per injector.
  2. Step 2: Analyze use case for 'any'

    Using 'any' is useful when you want separate instances in lazy-loaded modules.
  3. Final Answer:

    To get a new instance of the service in each lazy-loaded module. -> Option C
  4. Quick Check:

    'any' = new instance per injector, 'root' = singleton [OK]
Quick Trick: Use 'any' for separate instances in lazy modules [OK]
Common Mistakes:
MISTAKES
  • Confusing 'any' with 'root'
  • Thinking 'any' disables injection
  • Assuming 'any' shares instance globally

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes