Bird
0
0

You want to create a FormGroup that contains a nested FormGroup for address with controls street and city. Which code correctly does this?

hard🚀 Application Q8 of 15
Angular - Reactive Forms
You want to create a FormGroup that contains a nested FormGroup for address with controls street and city. Which code correctly does this?
Anew FormGroup({ address: { street: '', city: '' } })
Bnew FormGroup({ address: new FormGroup({ street: new FormControl(''), city: new FormControl('') }) })
Cnew FormGroup({ street: new FormControl(''), city: new FormControl('') })
Dnew FormGroup({ address: new FormControl({ street: '', city: '' }) })
Step-by-Step Solution
Solution:
  1. Step 1: Understand nested FormGroup structure

    Nested groups require FormGroup instances inside the parent FormGroup.
  2. Step 2: Analyze each option

    Only new FormGroup({ address: new FormGroup({ street: new FormControl(''), city: new FormControl('') }) }) correctly nests a FormGroup with FormControl children; others use raw objects or wrong types.
  3. Final Answer:

    new FormGroup({ address: new FormGroup({ street: new FormControl(''), city: new FormControl('') }) }) -> Option B
  4. Quick Check:

    Nested FormGroup = FormGroup inside FormGroup [OK]
Quick Trick: Nest FormGroups by placing FormGroup inside another FormGroup [OK]
Common Mistakes:
MISTAKES
  • Using plain objects instead of FormGroup
  • Putting FormControl with object value
  • Not nesting controls properly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes