我试图通过Angular应用中的HTTP DELETE
请求发送对象的ID,以删除 JSON 文件中的对象。
这是我的打字稿:
cancelOffer(offerId: number) {
console.log('OFFER ID: ' + offerId);
this.offerService.deleteOffer(offerId).subscribe(
() => {
console.log('Offer Deleted Successfully');
this.getAllOffers();
},
(err: any) => {
console.log(err);
this.errorMessage = <any>err;
});
}
这是我的Offer Service
代码:
baseUrl = 'http://localhost:3000/offers';
deleteOffer(id: number): Observable<void> {
console.log('Delete Offer Called');
return this.httpClient.delete<void>(`${this.baseUrl}/${id}`)
.pipe(catchError(this.handleError));
}
当我导航到http://localhost:3000/offers
时,将显示以下内容:
[
{
"id": 1,
"managerId": 1,
"jobId": 2,
"employeeId": 1
},
{
"id": 2,
"managerId": 4,
"jobId": 1,
"employeeId": 4
},
{
"id": 3,
"managerId": 8,
"jobId": 91,
"employeeId": 1
}
]
有人可以告诉我为什么我的代码如此行吗,以及我该如何解决?