Bird
0
0

Given this template snippet:

medium📝 component behavior Q13 of 15
Angular - Component Interaction
Given this template snippet:
<input #myInput type="text">
<button (click)="myInput.focus()">Focus</button>

What happens when the button is clicked?
ANothing happens because focus() is not a valid method
BAn error occurs because myInput is undefined
CThe input box receives keyboard focus
DThe button text changes to 'Focus'
Step-by-Step Solution
Solution:
  1. Step 1: Understand the template reference usage

    The #myInput references the input element, allowing direct access to its DOM methods.
  2. Step 2: Analyze the click event

    Click calls myInput.focus(), which sets keyboard focus on the input element.
  3. Final Answer:

    The input box receives keyboard focus -> Option C
  4. Quick Check:

    Template ref calls focus() = input focused [OK]
Quick Trick: Template refs access DOM methods like focus() [OK]
Common Mistakes:
  • Assuming template refs are undefined in event handlers
  • Thinking focus() is invalid on input elements
  • Expecting button text to change

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes