I have an angular reactive form with a nested form group
this.form = new FormGroup({
name: new FormControl(),
address: new FormGroup({
line1: new FormControl(),
line2: new FormControl()
})
});
If I call form.patchValue with an object containing the nested fields everything works fine as expected:
this.form.patchValue({
name: 'test',
address: {
line1: 'test line 1',
line2: 'test line 2'
}
});
However if the address property is null:
this.form.patchValue({
name: 'test',
address: null
});
I receive an error: Cannot convert undefined or null to object.
How can I get round this problem as the object returned from the server is valid and I have no control over it.
Example here: https://stackblitz.com/edit/angular-broncz
Thanks