链接不会从节点+ angular

时间:2018-12-31 10:26:03

标签: node.js angular http-status-code-500

当我单击删除按钮时,我在chrome dev中找到了具有ID的特定数据。工具,但永远不会从数据库中删除数据。我收到类似

的错误
  

删除http://localhost:3000/employee/5c29b718b9bc521ef8a91c3b 500(内部服务器错误)   core.js:14597错误HttpErrorResponse {标题:HttpHeaders,状态:500,statusText:“内部服务器错误”,url:“ http://localhost:3000/employee/5c29b718b9bc521ef8a91c3b”,好的:否,...}

控制器文件(节点):

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'});
        });
    }
}

0 个答案:

没有答案