javascript - *ngFor 内部 *ngFor
问题描述
我有一个保存用户订单的数组,其中还有另一个数组保存他的订购项目:
我的问题是:我如何遍历他的 orders[] -> orderItems[]
现在,我手动完成它只是为了确保它有效
HTML 文件:
<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 文件:
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);
})
}
}
赞赏!
解决方案
以下是如何呈现 html
<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>
推荐阅读
- c - 如何使用 WinSock2 在 C 中为客户端设置 IP 地址
- wordpress - 如何在 Wordpress 上的站点之间传输插件
- facebook-graph-api - Graph API 中的页面缺少连接的 Instagram 帐户字段
- javascript - 如何在 javascript 中使用 map() 从 javascript 对象中提取数据?
- php - 将数组分配给变量改变了类型?
- python - Python - 分数的分类和序列匹配器
- ios - iOS 将图像和文本共享到 UIActivityViewController 然后在 Objective-C 中出现错误
- python-3.6 - 在python中将字符串写入文件时出错
- ios - 可本地化字符串文件可以动态更改吗?
- php - 如何让来自两个不同 php 页面的变量一起显示在第三个 php 页面?