我试图显示用户的订单是一个个人资料页面,但收到该错误。
目前,我只是试图显示用户的名字
用户配置文件订单路由:
// 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">
,错误消失,但页面上未显示任何内容:
慕标琳琳
相关分类