-1

我想知道如何在数组中获取值*ngFor。首先我*ngFof用来获取项目列表。其次,我commonService.indexKey$.getValue()用来检查 id 是否commonService.quantityList$.getValue()可用这是我的代码

HTML

<div *ngFor="let item of commonService.quantityList$.getValue(); let i = index" class="Box">
<label>Qty : {{commonService.indexKey$.getValue()== item.id?item.quantity - commonService.indexKey$.getValue().count:item.quantity}}</label>
</div>

示例数据

commonService.quantityList$.getValue()

quantity = [
    { id:1, quantity:100 },
    { id:2, quantity:200 },
    { id:3, quantity:30 }
  ];

commonService.indexKey$.getValue()

indexCount = [
          {id: 1,count: 2},
          {id: 2,count: 3},
          {id: 3,count: 4},
        ]
4

1 回答 1

1

不确定您要在标签中做什么,因为您似乎正在进行比较“==”,因此标签将输出“true”或“false”。那是你真正想要的吗?

<div *ngFor="let item of commonService.quantityList$.getValue(); let i = index" class="Box">
<label>Qty : {{commonService.indexKey$.getValue()[i]== item.id?item.quantity - commonService.indexKey$.getValue()[i].count :item.quantity}}</label>
</div>
于 2020-12-29T04:25:30.717 回答