Bird
0
0

Why does Angular create multiple instances of a service when it is provided in both a lazy-loaded module and the root injector?

hard🧠 Conceptual Q10 of 15
Angular - Services and Dependency Injection
Why does Angular create multiple instances of a service when it is provided in both a lazy-loaded module and the root injector?
ABecause services cannot be singleton if provided anywhere
BBecause Angular merges all providers into one instance automatically
CBecause root injector overrides lazy module providers always
DBecause lazy-loaded modules have their own injector hierarchy separate from root
Step-by-Step Solution
Solution:
  1. Step 1: Understand Angular injector hierarchy

    Lazy-loaded modules have their own injectors separate from the root injector.
  2. Step 2: Explain multiple instances creation

    Providing service in both root and lazy module creates separate instances in each injector.
  3. Final Answer:

    Because lazy-loaded modules have their own injector hierarchy separate from root -> Option D
  4. Quick Check:

    Lazy modules have separate injectors causing multiple instances [OK]
Quick Trick: Lazy modules have separate injectors causing multiple instances [OK]
Common Mistakes:
MISTAKES
  • Assuming providers merge automatically
  • Thinking root injector overrides lazy module providers
  • Believing services can't be singleton anywhere

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes