【发布时间】:2022-01-20 22:17:56
【问题描述】:
我正在尝试修补我正在使用平均堆栈创建的项目中的任务。所有 api 的工作,但是当我尝试使用 id 参数修补元素时,出现错误:
"Object is possibly 'undefined'".
我想做的是:
- 获取具有精确 id 的元素
- 使用该 id 作为查询来修补该元素
这是代码:
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();
}
}
【问题讨论】:
标签: javascript angular typescript mongodb mean-stack