Bird
0
0

How can you pass a template reference variable of an input element to a child component's input property?

hard📝 Application Q9 of 15
Angular - Templates and Data Binding
How can you pass a template reference variable of an input element to a child component's input property?
A<child-comp inputElement="#inputRef"></child-comp> <input #inputRef type="text">
B<child-comp [inputElement]="inputRef"></child-comp> <input #inputRef type="text">
C<child-comp [inputElement]="#inputRef"></child-comp> <input #inputRef type="text">
D<child-comp [inputElement]="inputRef.value"></child-comp> <input #inputRef type="text">
Step-by-Step Solution
Solution:
  1. Step 1: Understand how to bind template refs to inputs

    You bind the variable name directly without # inside property binding.
  2. Step 2: Check which option uses correct binding syntax

    <child-comp [inputElement]="inputRef"></child-comp> <input #inputRef type="text"> correctly passes inputRef as a reference to the child component.
  3. Final Answer:

    Pass template ref variable directly without # in property binding -> Option B
  4. Quick Check:

    Use [prop]="inputRef" to pass template refs [OK]
Quick Trick: Pass template refs without # in property bindings [OK]
Common Mistakes:
  • Including # inside property binding
  • Passing inputRef.value instead of inputRef
  • Using string literals instead of variable

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes