Bird
0
0

In this Angular reactive form code:

medium📝 Debug Q7 of 15
Angular - Template-Driven Forms
In this Angular reactive form code:
this.userForm = new FormGroup({
age: new FormControl(18, [Validators.min(18), Validators.max(65)])
});
this.userForm.controls.age.setValue(70);
console.log(this.userForm.valid);

What will be logged and why?
Afalse, because setValue throws an error for invalid values.
Bfalse, because age 70 is outside the max validator limit.
Ctrue, because setValue bypasses validators.
Dtrue, because 70 is a valid number.
Step-by-Step Solution
Solution:
  1. Step 1: Understand Validators.min and Validators.max

    The age control requires values between 18 and 65 inclusive.
  2. Step 2: Check validity after setting age to 70

    Setting age to 70 violates Validators.max(65), so form becomes invalid.
  3. Final Answer:

    false, because age 70 is outside the max validator limit. -> Option B
  4. Quick Check:

    Form validity reflects validator rules [OK]
Quick Trick: Validators enforce rules; invalid values make form invalid [OK]
Common Mistakes:
MISTAKES
  • Thinking setValue ignores validators
  • Expecting errors thrown on invalid setValue
  • Assuming 70 is valid for max 65

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes