когда я нажимаю кнопку удаления, я нахожу определенные данные с идентификатором в chrome dev.инструмент, но никогда не удаляйте данные из базы данных.Я получаю сообщение об ошибке типа
DELETE http://localhost:3000/employee/5c29b718b9bc521ef8a91c3b 500 (Внутренняя ошибка сервера) core.js: 14597 ОШИБКА HttpErrorResponse {заголовки: HttpHeaders, status: 500, statusText: «Internal Server Error», url: "http://localhost:3000/employee/5c29b718b9bc521ef8a91c3b", ok: false,…}
файл контроллера (узел):
router.delete('/:id', (req,res) => {
if(!objectId.isValid(res.params.id)){
return res.status(400).send(`no record found for given id : ${ $res.params.id }`);
} else {
Employee.findByIdAndDelete(req.body.id, (error,docs) => {
if(!error)
{
res.send(docs);
} else {
console.log('Error in employee Delete :' + JSON.stringify(error,undefined,2));
}
});
}
});
служебный файл (угловой) enter code here
файл component.ts (угловой)
deleteEmployee(_id:string)
{
return this.http.delete(this.baseURL + `/${_id}`);
}
// delete employee
onDelete(_id: string,form :NgForm){
if(confirm('are you sure remove this data .. ?') == true){
this.employeeService.deleteEmployee(_id).subscribe((res) => {
this.refreshEmployeeList();
this.resetForm(form);
M.toast({html: 'delete sucessfully', classes: 'rounded'});
});
}
}