Bird
0
0

Given this component code:

medium📝 component behavior Q4 of 15
Angular - Templates and Data Binding
Given this component code:
export class AppComponent {
  message = 'Hello';
}

And this template:
<input [(ngModel)]="message">
<p>{{ message }}</p>

What happens when the user types 'Hi' in the input box?
AThe paragraph text stays 'Hello' until the input loses focus
BThe paragraph text updates to 'Hi' immediately
CThe input box clears automatically
DAn error occurs because message is not updated
Step-by-Step Solution
Solution:
  1. Step 1: Understand two-way binding behavior

    With [(ngModel)], changes in the input update the component property immediately.
  2. Step 2: Check the template binding

    The paragraph uses interpolation to show the current value of message, so it updates as message changes.
  3. Final Answer:

    The paragraph text updates to 'Hi' immediately -> Option B
  4. Quick Check:

    Two-way binding updates view instantly = A [OK]
Quick Trick: ngModel updates component and view instantly [OK]
Common Mistakes:
  • Thinking update waits for blur event
  • Expecting input to clear
  • Assuming error on update
  • Confusing one-way binding behavior

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes