[英]Err: Cannot find a differ supporting object '[object Object]' of type 'object'
I'm trying to show the user's orders in is a profile page, but receiving that error.我试图在个人资料页面中显示用户的订单,但收到该错误。
For now, Im just trying to show the user's first name现在,我只是想显示用户的名字
User Profile Orders routing:用户配置文件订单路由:
// User Profile (Orders)
userRouter.get('/profile/orders',verify,(req,res) =>{
OrderDetails.find({UserId: req.user._id})
.then(user => {
res.status(200).json({
Orders:user
});
});
});
User service:用户服务:
getProfileOrders(){
const token = localStorage.getItem('id_token');
let headers = new HttpHeaders({
'Content-Type': 'application/json',
'auth-token': token
});
const httpOptions = {
headers: headers
};
return this.http.get(`${this.uri}/user/profile/orders`, httpOptions)
}
}
User profile orders.ts:用户个人资料 orders.ts:
export class ProfileOrdersComponent implements OnInit {
myOrders: OrderDetails[];
constructor(private userService : UserService) { }
ngOnInit() {
this.userService.getProfileOrders().subscribe((data:OrderDetails[]) =>{
this.myOrders = data
console.log(this.myOrders);
})
}
HTML page: HTML 页面:
<div class = "container">
<div *ngFor = "let order of myOrders">
<h4>first name is: {{order.firstName}}</h4>
</div>
</div>
By doing:通过做:
<div *ngFor = "let order of myOrders | keyvalue">
, the error disappears, but nothing is shown on the page: ,错误消失,但页面上没有显示任何内容:
Much Appreciated!非常感激!
Your orders are actually set as the value of the Orders
key.您的订单实际上设置为Orders
键的值。
Try using the Orders
from your data尝试使用数据中的Orders
this.myOrders = data.Orders;
You could also modify your service to map the returned result instead您也可以将服务修改为 map 返回的结果
return this.http.get(`${this.uri}/user/profile/orders`, httpOptions)
.pipe(map(res => res.Orders));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.