Bird
0
0

Identify the error in this code snippet:

medium📝 Debug Q6 of 15
Angular - Reactive Forms
Identify the error in this code snippet:
this.form = this.fb.group({
username: this.fb.control(''),
age: ''
});
ANo error, code is correct
Busername should be a string, not fb.control()
Cage should be created using fb.control()
Dfb.group() cannot contain controls
Step-by-Step Solution
Solution:
  1. Step 1: Check form group control definitions

    FormBuilder.group() accepts plain initial values like strings or FormControl instances.
  2. Step 2: Verify both definitions

    username: this.fb.control('') creates a FormControl, age: '' provides initial value '' -- both valid, no error.
  3. Final Answer:

    No error, code is correct -> Option A
  4. Quick Check:

    Mixing plain values and fb.control() in group OK [OK]
Quick Trick: Plain values or fb.control() both valid in group [OK]
Common Mistakes:
MISTAKES
  • Thinking fb.group cannot mix controls with plain values
  • Believing all controls must use fb.control()
  • Confusing group() with FormArray requirements

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes