Bird
0
0

Given this Angular template snippet:

medium📝 state output Q13 of 15
Angular - Template-Driven Forms
Given this Angular template snippet:
<form #f="ngForm">
  <input name="email" ngModel required>
  <button [disabled]="!f.form.valid">Submit</button>
</form>

What happens to the Submit button when the input is empty?
AThe Submit button is enabled regardless of input.
BThe Submit button is disabled only if the input is touched.
CThe Submit button is disabled because the form is invalid.
DThe Submit button is enabled only if the input is dirty.
Step-by-Step Solution
Solution:
  1. Step 1: Understand form validity with required input

    The input has the required attribute, so if empty, the form is invalid.
  2. Step 2: Analyze the button's disabled binding

    The button is disabled when !f.form.valid is true, meaning when the form is invalid.
  3. Final Answer:

    The Submit button is disabled because the form is invalid. -> Option C
  4. Quick Check:

    Required empty input disables button = B [OK]
Quick Trick: Button disabled if form invalid (required empty input) [OK]
Common Mistakes:
MISTAKES
  • Thinking button enables on untouched input
  • Confusing dirty and valid states
  • Ignoring required validation effect

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes