-
Notifications
You must be signed in to change notification settings - Fork 27.1k
Reactive Form - Formgroup with a nested formgroup throw exception on reset call with null values #20509
Description
[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report
[X] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question
Current behavior
When i call form reset on a formGroup with nested formGroup passing it with a null value i receive a error "Cannot read property ... of null"
Expected behavior
Expected result is that on form reset with a null value the nested form group properties become all null.
Minimal reproduction of the problem with instructions
When i have a formGroup with a nested formGroup like this:
let form = this.fb.group({
Id: [null],
Nested: fb.group({
Id: [null]
})
})
If i call a form reset or a patch value with a object like this:
form.reset({
Id: 1,
Nested: null
})
i receive the error "Cannot read property 'Id' of null" because he try to read the nested property from a null object
Expected result is that on form reset with a null value the nested form group properties become all null. This behavior happen when i call the reset without the nested properties:
form.reset({Id: 3})
What is the motivation / use case for changing the behavior?
Usually service return models with all properties and nested entities null if they don't exist instead return the nested entities initialized