Bird
0
0

What will happen if you try to import a service without adding it to providers or using providedIn in Angular?

medium📝 Predict Output Q5 of 15
Angular - Fundamentals
What will happen if you try to import a service without adding it to providers or using providedIn in Angular?
AThe service works normally without any configuration
BAngular throws a runtime error when injecting the service
CAngular automatically adds it to providers
DThe service is tree-shaken and removed
Step-by-Step Solution
Solution:
  1. Step 1: Recall Angular dependency injection rules

    Services must be provided via providers array or providedIn to be injectable.
  2. Step 2: Consequence of missing provider

    Without provider, Angular cannot create the service instance and throws an error at runtime.
  3. Final Answer:

    Angular throws a runtime error when injecting the service -> Option B
  4. Quick Check:

    Missing provider = runtime error = A [OK]
Quick Trick: Always provide services to avoid injection errors [OK]
Common Mistakes:
  • Assuming Angular auto-provides services
  • Thinking service works without provider
  • Confusing tree-shaking with missing provider errors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes