我试图显示用户的订单是一个个人资料页面,但收到该错误。目前,我只是试图显示用户的名字用户配置文件订单路由:// User Profile (Orders)userRouter.get('/profile/orders',verify,(req,res) =>{ OrderDetails.find({UserId: req.user._id}) .then(user => { res.status(200).json({ Orders:user }); });});用户服务: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) }}用户配置文件 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); })}网页:<div class = "container"><div *ngFor = "let order of myOrders"> <h4>first name is: {{order.firstName}}</h4></div></div>通过执行:<div *ngFor = "let order of myOrders | keyvalue">,错误消失,但页面上未显示任何内容:
1 回答
慕标琳琳
TA贡献1830条经验 获得超9个赞
您的订单实际上被设置为密钥的值。Orders
尝试使用 来自您的数据Orders
this.myOrders = data.Orders;
您还可以修改服务以映射返回的结果
return this.http.get(`${this.uri}/user/profile/orders`, httpOptions) .pipe(map(res => res.Orders));
添加回答
举报
0/150
提交
取消