Bird
0
0

Which of these is a valid way to provide a service only in a specific Angular module using @Injectable?

easy🧠 Conceptual Q2 of 15
Angular - Services and Dependency Injection
Which of these is a valid way to provide a service only in a specific Angular module using @Injectable?
AUse <code>providedIn: SomeModule</code> where SomeModule is the module class.
BUse <code>providedIn: 'root'</code> in the service decorator.
CUse <code>providedIn: 'any'</code> in the service decorator.
DUse <code>providedIn: 'platform'</code> in the service decorator.
Step-by-Step Solution
Solution:
  1. Step 1: Recall how to scope service to a module

    Angular allows providing a service in a specific module by passing the module class to providedIn.
  2. Step 2: Identify correct syntax

    Using providedIn: SomeModule (the module class) scopes the service to that module only.
  3. Final Answer:

    Use providedIn: SomeModule where SomeModule is the module class. -> Option A
  4. Quick Check:

    Module class in providedIn = module-scoped service [OK]
Quick Trick: Use module class in providedIn to limit service scope [OK]
Common Mistakes:
MISTAKES
  • Using 'root' provides app-wide, not module-only
  • Using 'any' provides a new instance per injector
  • Confusing 'platform' with module scope

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes