For an application I'm building, I'm retrieving data from an API and setting my form value directly with that response. For that I'm using the reactive forms module. I've built the form so that it matches the object I'm getting from the API. The problem is that some fields are supposed to be an object (FormGroup), but are NULL when empty. This results in the error "Cannot convert undefined or null to object".
FormGroup instance:
note: this.formBuilder.group({
turnbook_file: [''],
note: [''],
additional_files: ['']
});
Response from API
note: NULL
My thought was that maybe it's possibile to put an OR statement or something where you define the FormGroup like this:
note: this.formBuilder.group({
turnbook_file: [''],
note: [''],
additional_files: ['']
} | NULL);
patchValuebut in the question is about building the form. What's wrong with building/patching a first level control and only build/patch the second level group only after a check If you have a data? - trungk18