Arrays 在ngfor中获取数组中的值
我想知道如何在Arrays 在ngfor中获取数组中的值,arrays,angular,typescript,Arrays,Angular,Typescript,我想知道如何在*ngFor中获取数组中的值。首先,我使用*ngFof获取项目列表。其次,我使用commonService.indexKey$.getValue()检查commonService.quantityList$.getValue()中的id是否可用 这是我的密码 HTML commonService.indexKey$.getValue() 不确定您在标签中真正想做什么,因为您似乎正在进行比较“==”,因此标签将输出“真”或“假”。这是您真正想要的吗 <div *ngFor=&q
*ngFor
中获取数组中的值。首先,我使用*ngFof
获取项目列表。其次,我使用commonService.indexKey$.getValue()
检查commonService.quantityList$.getValue()中的id是否可用
这是我的密码
HTML
commonService.indexKey$.getValue()
不确定您在标签中真正想做什么,因为您似乎正在进行比较“==”,因此标签将输出“真”或“假”。这是您真正想要的吗
<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>
数量:{{commonService.indexKey$.getValue()[i]==item.id?item.quantity-commonService.indexKey$.getValue()[i]。计数:item.quantity}
这不是在stackoverflow中提问的方式。首先,你需要理解它,并提出一个清晰完整的问题。其他智者会浪费其他人的时间。谢谢你的回答。但我得到了错误`无法读取未定义的属性'计数'`两个数组的长度是否相同?不相同的长度您可以尝试用简单的语言解释它们是什么数组,您希望在标签中显示什么?现在您正在尝试减去两个不同长度的数组(不可能!),并与“==”进行比较。您可以编辑您的问题并添加两个具有值和预期结果的数组示例吗?谢谢!
quantity = [
{ id:1, quantity:100 },
{ id:2, quantity:200 },
{ id:3, quantity:30 }
];
indexCount = [
{id: 1,count: 2},
{id: 2,count: 3},
{id: 3,count: 4},
]
<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>