Bird
0
0

Which of the following is the correct way to inject a facade service MyFacadeService into an Angular component constructor?

easy📝 Syntax Q12 of 15
Angular - Advanced Patterns

Which of the following is the correct way to inject a facade service MyFacadeService into an Angular component constructor?

Aconstructor(private myFacadeService: MyFacadeService) {}
Bconstructor(public MyFacadeService) {}
Cconstructor(myFacadeService: new MyFacadeService()) {}
Dconstructor(private myFacadeService = MyFacadeService) {}
Step-by-Step Solution
Solution:
  1. Step 1: Recall Angular dependency injection syntax

    Angular injects services via constructor parameters with access modifiers and type annotations.
  2. Step 2: Match correct syntax

    constructor(private myFacadeService: MyFacadeService) {} uses private and type MyFacadeService, which is correct.
  3. Final Answer:

    constructor(private myFacadeService: MyFacadeService) {} -> Option A
  4. Quick Check:

    Inject service with private + type [OK]
Quick Trick: Use private and type in constructor for injection [OK]
Common Mistakes:
  • Omitting access modifier (private/public)
  • Using new keyword inside constructor parameters
  • Assigning service without type annotation

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes