node.js - 如何获得特定对象的角度
问题描述
我使用 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 谢谢
解决方案
你最好 console.log({data}) 先看看你从后端得到了什么。尝试这个:
this.customerService.getCustomer(id).subscribe(data => {
console.log({data});
const { customer } = data;
this.customer = customer;
console.log(this.customer);
},error => this.onWarning('Error'));
推荐阅读
- wordpress - Woocommerce - 如果在结帐期间登录,则删除所有旧购物车物品
- react-native - React-Native/Redux-Saga:如何等待调度完成
- xamarin - TabbedPage 上的 Retap 事件
- java - 使用 Log4j 为同一类分隔日志文件
- osgi - 如何在 OSGi 中编写工厂模式?
- sql - 截断和更新数据库表中的字符串值
- docker - Docker MailDev 中的电子邮件中的换行符
- reactjs - react-redux 桌面应用程序中请求的资源错误中不存在 Access-Control-Allow-Origin' 标头
- php - 如何在 .htaccess 的帮助下在 php 中重定向多个文件
- java - 如何从 PrintWriter 写入的文件中读取对象