Bird
0
0

Identify the error in this service declaration:

medium📝 Debug Q14 of 15
Angular - Services and Dependency Injection
Identify the error in this service declaration:
 @Injectable({
   providedIn: root
 })
 export class LoggerService {}
AIncorrect decorator name, should be @InjectableService
BService class must have a constructor
CMissing quotes around 'root' in providedIn
DprovidedIn cannot be used in @Injectable
Step-by-Step Solution
Solution:
  1. Step 1: Check syntax of providedIn value

    The value 'root' must be a string, so it needs quotes: 'root'. Without quotes, it's treated as an undefined variable.
  2. Step 2: Verify other parts

    The decorator name @Injectable is correct, constructor is optional, and providedIn is valid here.
  3. Final Answer:

    Missing quotes around 'root' in providedIn -> Option C
  4. Quick Check:

    String values need quotes in providedIn [OK]
Quick Trick: Always put quotes around string values in decorators [OK]
Common Mistakes:
MISTAKES
  • Omitting quotes around 'root'
  • Confusing decorator names
  • Thinking constructor is mandatory

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes