Bird
0
0

What is wrong with this Angular code snippet?

medium📝 Debug Q6 of 15
Angular - Reactive Forms
What is wrong with this Angular code snippet?
this.form = new FormGroup({
email: FormControl('')
});
AFormControl should be imported from '@angular/forms'
BFormGroup cannot have only one control
CMissing 'new' keyword before FormControl instantiation
DFormGroup requires an array, not an object
Step-by-Step Solution
Solution:
  1. Step 1: Check FormControl instantiation

    FormControl must be instantiated with the 'new' keyword.
  2. Step 2: Analyze the code

    The code uses FormControl('') without 'new', which causes an error.
  3. Step 3: Review other options

    FormGroup cannot have only one control is false; FormGroup can have one control. FormControl should be imported from '@angular/forms' is unrelated to the snippet error. FormGroup requires an array, not an object is incorrect; FormGroup takes an object.
  4. Final Answer:

    Missing 'new' keyword before FormControl instantiation -> Option C
  5. Quick Check:

    Always use 'new' with FormControl [OK]
Quick Trick: Instantiate FormControl with 'new' keyword [OK]
Common Mistakes:
MISTAKES
  • Omitting 'new' before FormControl
  • Confusing object and array syntax for FormGroup
  • Assuming FormGroup needs multiple controls

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes