Bird
0
0

Which syntax correctly injects Renderer2 in a directive's constructor?

easy📝 Syntax Q12 of 15
Angular - Directives
Which syntax correctly injects Renderer2 in a directive's constructor?
Aconstructor(renderer: Renderer2 private) {}
Bconstructor(Renderer2 private renderer) {}
Cconstructor(private Renderer2 renderer) {}
Dconstructor(private renderer: Renderer2) {}
Step-by-Step Solution
Solution:
  1. Step 1: Recall Angular dependency injection syntax

    Angular uses TypeScript constructor parameters with access modifiers like 'private' before the variable name and type after the colon.
  2. Step 2: Match correct syntax

    constructor(private renderer: Renderer2) {} follows the pattern: 'constructor(private renderer: Renderer2) {}'. Other options have incorrect order or missing colons.
  3. Final Answer:

    constructor(private renderer: Renderer2) {} -> Option D
  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
  • Omitting colon between name and type
  • Placing access modifier after type

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes