Bird
0
0

Given this Angular template snippet:

medium📝 Predict Output Q4 of 15
Angular - Template-Driven Forms
Given this Angular template snippet:
<form #myForm="ngForm">
  <input name="email" ngModel required pattern="^[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}$">
  <button [disabled]="myForm.invalid">Submit</button>
</form>

What happens when the user types 'user@example' and tries to submit?
AThe form resets automatically.
BThe form submits successfully because 'required' is satisfied.
CThe submit button is enabled but submission fails with an error.
DThe submit button remains disabled because the pattern is not matched.
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the pattern validation

    The pattern requires a valid email format with a domain suffix. 'user@example' lacks the '.com' or similar suffix, so it fails pattern validation.
  2. Step 2: Check form validity and button state

    Since pattern validation fails, myForm.invalid is true, disabling the submit button.
  3. Final Answer:

    The submit button remains disabled because the pattern is not matched. -> Option D
  4. Quick Check:

    Pattern mismatch disables submit button [OK]
Quick Trick: Invalid pattern disables submit button via form.invalid [OK]
Common Mistakes:
MISTAKES
  • Assuming 'required' alone enables submit
  • Thinking form submits despite pattern failure
  • Expecting automatic form reset on invalid input

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes