错误:找不到类型为“对象”的不同支持对象“[对象]”

我试图显示用户的订单是一个个人资料页面,但收到该错误。


目前,我只是试图显示用户的名字


用户配置文件订单路由:


// 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">

,错误消失,但页面上未显示任何内容:

http://img.mukewang.com/62fdf6c00001a79c18220792.jpg

http://img3.mukewang.com/62fdf6cd0001b02304800136.jpg

倚天杖
浏览 109回答 1
1回答

慕标琳琳

您的订单实际上被设置为密钥的值。Orders尝试使用 来自您的数据Ordersthis.myOrders&nbsp;=&nbsp;data.Orders;您还可以修改服务以映射返回的结果return&nbsp;this.http.get(`${this.uri}/user/profile/orders`,&nbsp;httpOptions) .pipe(map(res&nbsp;=>&nbsp;res.Orders));
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript