简体   繁体   English

错误:找不到支持 object '[object Object]' 类型 'object' 的差异

[英]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.

相关问题 在角度6中找不到类型为“对象”的其他支持对象“ [对象对象]” - Cannot find a differ supporting object '[object Object]' of type 'object' in angular 6 Angular 7 找不到类型为“object”的不同支持对象“[object Object]”。 NgFor 只支持绑定到 Iterables,比如 Arrays - Angular 7 Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Arrays 错误找不到类型为“对象”的其他支持对象“ [对象对象]”。 NgFor仅支持绑定到可迭代对象,例如数组 - ERROR Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Arrays Angular 9 找不到支持“对象”类型的 object“[对象对象]”的不同。 NgFor 仅支持绑定到诸如 Arrays 之类的 Iterables - Angular 9 Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Arrays 找不到支持 object 类型为“object”的“[object Object]”的差异。 NgFor 只支持绑定到 Iterables,比如 Arrays - Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables, such as Arrays 错误错误:在 Angular 项目上找不到支持类型为“object”的 object“[object Object]”的差异 - ERROR Error: Cannot find a differ supporting object '[object Object]' of type 'object' on Angular Project 错误:找不到类型为“对象”的其他支持对象“ [对象对象]”。 NgFor仅支持绑定到Iterables - Error: Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables 流星集合中找不到类型为“对象”的其他支持对象“ [对象对象]” - Cannot find a differ supporting object '[object Object]' of type 'object' , Error in meteor Collections 找不到支持“object”类型的 object“[object Object]”的不同,但它已经是一个数组 - Cannot find a differ supporting object '[object Object]' of type 'object' , but it's already an array 迭代数组中的数组时出错:“找不到支持 object '[object Object]' 类型为 'object' 的不同。” - Error when iterating over array within array: “Cannot find a differ supporting object '[object Object]' of type 'object'.”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM