【发布时间】:2021-03-22 16:50:55
【问题描述】:
我使用 angular 作为前端,而 node.js 使用 mongodb 作为后端。我想通过给定的_id获取特定的客户对象。我创建了 node.js 方法并能够使用邮递员发送请求并能够获得结果。但我无法将输出发送到前端。能否给出以表格或段落形式输出结果的解决方案。
Node.js 代码:
const getCustomer = (req, resp) => {
let {id} = req.params;
CustomerSchema.findById(id).then(result =>{
resp.status(200).json(result);
}).catch(error =>{
resp.status(500).json(result);
})
};
角码:
private setCustomerToForm() {
this.route.params.subscribe(params => {
const id = params['id'];
if (!id){
return;
}
this.customerService.getCustomer(id).subscribe(customer => {
this.customer = customer;
console.log(this.customer)
},error => this.onWarning('Error'));
});
}
客户 DTO 包含 CustomerName、CustomerNic 谢谢你
【问题讨论】:
-
添加
this.customerService.getCustomer(id)的定义 -
我添加了 noh..查看我的代码
-
不,您没有添加包含
getCustomer定义的服务文件。 -
构造函数(私有toastr:ToastrService,私有customerService:CustomerService,私有路由器:路由器,私有对话:MatDialog,私有路由:ActivatedRoute,){ this.loadAll(); }
-
请添加您服务中的代码。
标签: node.js angular mongodb typescript