I am encountering an issue while trying to update a task in my project built with the MEAN stack. Although all APIs are functioning properly, I am facing an error when attempting to patch an element using the ID parameter. The error message displayed is:
"Object is possibly 'undefined'".
My objective is as follows:
- Retrieve the element based on a specific ID
- Utilize that ID as a query to update the corresponding element
Below is the code snippet:
export class TaskServicesService {
constructor(private myHttp: HttpClient) { }
async updateTask(payload: any) : Promise<any> {
const task = await this.myHttp.get('http://localhost:3000/').toPromise();
const elId: any = task.id;
return await this.myHttp.patch('http://localhost:3000/list/', {title: payload}).toPromise();
}
}