首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >*ngFor内部*ngFor

*ngFor内部*ngFor
EN

Stack Overflow用户
提问于 2020-05-17 10:41:38
回答 1查看 635关注 0票数 0

我有一个数组,该数组包含一个用户的订单,其中还有另一个数组,它保存着他订购的项目:

我的问题是:如何循环遍历他的orders[] -> orderItems[]

现在,我手动做它只是为了确保它能工作。

HTML文件:

代码语言:javascript
复制
 <tbody class="text-center">
                <tr *ngFor = "let order of myOrders;">
                    <td>{{order.orderItems[0].product_Name}}</td>
                    <td>{{order.orderItems[0].product_Price | currency: '$'}}</td>
                    <td>{{order.orderItems[0].product_Quantity}}</td>
                    <td colspan="6">{{order.orderItems[0].product_Price* order.orderItems[0].product_Quantity | currency: '$'}}</td>
                </tr>
                
            </tbody>

TS文件:

代码语言:javascript
复制
export class ProfileOrdersComponent implements OnInit {

  myOrders: OrderDetails[];
  constructor(private userService : UserService) { }

  ngOnInit() {
    this.userService.getProfileOrders().subscribe((data:OrderDetails[]) =>{
      this.myOrders = data
      console.log("My Orders:", this.myOrders);
    })
  }

}

感谢你!

EN

回答 1

Stack Overflow用户

发布于 2020-05-17 11:06:55

下面是如何呈现html

代码语言:javascript
复制
<tbody class="text-center">
  <tr *ngFor="let order of myOrders;">
    <td>
      <table>
        <tr *ngFor="let orderItem of order.orderItems">
          <td>{{orderItem.product_Name}}</td>
          <td>{{orderItem.product_Price | currency: '$'}}</td>
          <td>{{orderItem.product_Quantity}}</td>
          <td colspan="6">{{orderItem.product_Price* orderItem.product_Quantity | currency: '$'}}</td>
        </tr>
      </table>
    </td>
  </tr>

</tbody>

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61850480

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档