Bird
0
0

Which syntax correctly injects a service named StateService into a component constructor?

easy📝 Syntax Q3 of 15
Angular - State Management
Which syntax correctly injects a service named StateService into a component constructor?
Aconstructor(private stateService: StateService) {}
Bconstructor(StateService private stateService) {}
Cconstructor(private StateService: stateService) {}
Dconstructor(stateService: StateService private) {}
Step-by-Step Solution
Solution:
  1. Step 1: Recall Angular dependency injection syntax

    Angular injects services via constructor parameters with access modifiers and type.
  2. Step 2: Match correct parameter order and casing

    The correct order is access modifier, parameter name, colon, then type.
  3. Final Answer:

    constructor(private stateService: StateService) {} -> Option A
  4. Quick Check:

    Correct DI syntax = private name: Type [OK]
Quick Trick: Use 'private name: Type' in constructor for DI [OK]
Common Mistakes:
  • Swapping parameter order
  • Incorrect casing of variable or type
  • Missing access modifier

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes