Bird
0
0

Given this code:

medium📝 Predict Output Q5 of 15
Angular - Reactive Forms
Given this code:
const form = this.fb.group({email: ['', Validators.required]});
console.log(form.controls.email.valid);

What will be logged initially?
Atrue
BError: Validators not imported
Cundefined
Dfalse
Step-by-Step Solution
Solution:
  1. Step 1: Understand Validators.required effect

    The control is initialized with an empty string and a required validator, so it is invalid initially.
  2. Step 2: Check valid property

    Since the control is empty and required, valid will be false.
  3. Final Answer:

    false -> Option D
  4. Quick Check:

    Empty required control is invalid = false [OK]
Quick Trick: Empty required fields start as invalid (valid = false) [OK]
Common Mistakes:
MISTAKES
  • Assuming valid is true initially
  • Confusing valid with touched
  • Expecting error without import

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes