In my Angular-12, I have this code:
editForm: FormGroup;
onSubmit() {
// Stop processing form submission if form data is invalid //
if (this.editForm.invalid) {
return;
}
// processing form submission data to server //
const formData = new FormData();
formData.append('heading', this.editForm.get('heading').value);
formData.append('title', this.editForm.get('title').value);
formData.append('image', this.editForm.get('image').value);
formData.append('description', this.editForm.get('description').value);
formData.append('id', this.editForm.get('id').value);
this.http.post(this.serverUrl + 'updateAbout', formData).subscribe((res: any) => {
this.router.navigate(['admin/about']).then(() => this.showToasterSuccess(res.message));
},
error => this.router.navigate(['admin/about']).then(() => this.showToasterError(error[0].message))
);
}
We got this error:
Object is possibly 'null'.ts(2531)
and this is highlighted:
formData.append('heading', this.editForm.get('heading').value);
I applied some of the similar solutions in stackoverflow, but none is working.
For instance, in tsconfig.json, I added "strictNullChecks": true to:
"angularCompilerOptions": {
"enableI18nLegacyMessageIdFormat": false,
"strictInjectionParameters": true,
"strictInputAccessModifiers": true,
"strictTemplates": true,
"strictNullChecks": true
}
But the problem is still not resolved.
How do I get it sorted out?
Thanks