Bird
0
0

Which of the following is the correct syntax to use @ContentChild to get a reference to a template variable named myRef?

easy📝 Syntax Q12 of 15
Angular - Component Interaction
Which of the following is the correct syntax to use @ContentChild to get a reference to a template variable named myRef?
A@ContentChild('myRef') myElement!: ElementRef;
B@ContentChild(myRef) myElement!: ElementRef;
C@ContentChild(#myRef) myElement!: ElementRef;
D@ContentChild(myRef, {static: true}) myElement!: ElementRef;
Step-by-Step Solution
Solution:
  1. Step 1: Correct syntax for @ContentChild selector

    The selector must be a string matching the template variable name, so it should be quoted: 'myRef'.
  2. Step 2: Static option usage

    Static option is optional and usually false by default; not required here.
  3. Final Answer:

    @ContentChild('myRef') myElement!: ElementRef; -> Option A
  4. Quick Check:

    Use quotes around template variable name in @ContentChild [OK]
Quick Trick: Use quotes around template variable name in @ContentChild [OK]
Common Mistakes:
  • Omitting quotes around the selector string
  • Using # inside the selector string
  • Confusing static option necessity

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes