Bird
0
0

You want to disable the Submit button only after the user has changed any input in the form and the form is invalid. Which condition correctly uses ngForm states to achieve this?

hard🚀 Application Q15 of 15
Angular - Template-Driven Forms
You want to disable the Submit button only after the user has changed any input in the form and the form is invalid. Which condition correctly uses ngForm states to achieve this?
A[disabled]="myForm.form.invalid && myForm.form.dirty"
B[disabled]="myForm.invalid || myForm.pristine"
C[disabled]="!myForm.form.valid && myForm.touched"
D[disabled]="myForm.form.valid && myForm.dirty"
Step-by-Step Solution
Solution:
  1. Step 1: Understand form state properties

    myForm.form.invalid is true if form is invalid; myForm.form.dirty is true if user changed any input.
  2. Step 2: Match condition to requirement

    We want to disable the button only if form is invalid AND user has changed input, so both must be true.
  3. Final Answer:

    [disabled]="myForm.form.invalid && myForm.form.dirty" -> Option A
  4. Quick Check:

    Disable if invalid and dirty = A [OK]
Quick Trick: Use invalid AND dirty to disable after user changes invalid form [OK]
Common Mistakes:
MISTAKES
  • Using OR instead of AND for disabling
  • Confusing touched with dirty
  • Checking valid instead of invalid

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes