Bird
0
0

In Angular, given this template snippet:

medium📝 component behavior Q4 of 15
Angular - Template-Driven Forms
In Angular, given this template snippet:
<input [formControl]="emailControl">
<div *ngIf="emailControl.invalid && emailControl.touched">Invalid email address</div>

What happens if the user clicks into the input, enters an invalid email, then clicks away?
ANo message will be shown because the control is not dirty.
BThe message 'Invalid email address' will be displayed.
CThe message will show only if the form is submitted.
DThe message appears immediately when the user starts typing.
Step-by-Step Solution
Solution:
  1. Step 1: Understand the condition

    The error message is shown when emailControl.invalid and emailControl.touched are both true.
  2. Step 2: User interaction

    The user focuses the input (making it touched), enters invalid data (making it invalid), then leaves the input.
  3. Final Answer:

    The message 'Invalid email address' will be displayed. -> Option B
  4. Quick Check:

    Invalid and touched triggers error display [OK]
Quick Trick: Errors show when invalid and touched are true [OK]
Common Mistakes:
MISTAKES
  • Confusing 'dirty' with 'touched' for showing errors
  • Expecting errors to show before leaving the input
  • Assuming errors show only on form submit

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes