form.value after initialization?import { FormGroup, FormControl } from '@angular/forms'; const form = new FormGroup({ firstName: new FormControl('Alice'), lastName: new FormControl('Smith') }); console.log(form.value);
The FormGroup's value property returns an object with keys matching the control names and their current values. Since each FormControl was initialized with a string, those strings appear in the value.
form.value after updating the nested control?import { FormGroup, FormControl } from '@angular/forms'; const form = new FormGroup({ user: new FormGroup({ email: new FormControl('user@example.com'), password: new FormControl('1234') }) }); form.get('user.email')?.setValue('new@example.com'); console.log(form.value);
Updating a nested FormControl inside a FormGroup updates the nested object in the FormGroup's value. The structure remains nested.
FormGroup requires an object where each key is a control name and each value is a FormControl instance. Option C follows this pattern.
import { FormGroup, FormControl } from '@angular/forms'; const form = new FormGroup({ email: new FormControl('test@example.com') }); form.get('password').setValue('12345');
The FormGroup only has a control named 'email'. Trying to get 'password' returns null. Calling setValue on null causes a runtime error.
A FormGroup is valid only if every control it contains, including those inside nested FormGroups, is valid. If any nested control is invalid, the whole FormGroup is invalid.