Bird
0
0

Given this reactive form control initialization:

medium📝 Predict Output Q4 of 15
Angular - Reactive Forms
Given this reactive form control initialization:
this.form = new FormGroup({
email: new FormControl('', [Validators.required, Validators.email])
});
this.form.controls.email.markAsTouched();
console.log(this.form.controls.email.touched);

What will be logged to the console?
Atrue
Bfalse
Cundefined
Dnull
Step-by-Step Solution
Solution:
  1. Step 1: Understand markAsTouched() effect

    Calling markAsTouched() sets the control's touched state to true.
  2. Step 2: Check the touched property after calling markAsTouched()

    Since markAsTouched() was called, touched is true and will be logged as true.
  3. Final Answer:

    true -> Option A
  4. Quick Check:

    markAsTouched() sets touched = true [OK]
Quick Trick: markAsTouched() sets touched to true immediately [OK]
Common Mistakes:
MISTAKES
  • Assuming touched remains false without user interaction
  • Confusing touched with dirty
  • Expecting undefined or null instead of boolean

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes