Angular 来自*ngFor循环的角度和动态数据,以获得总计、小计和增值税值(%16)

Angular 来自*ngFor循环的角度和动态数据,以获得总计、小计和增值税值(%16),angular,Angular,所以我有个问题。我需要根据*ngFor循环中的动态数据计算tag.price的动态总计,以及小计和增值税。下面是我的html和ts代码。小计、合计和增值税值将在该块下方的循环之外。任何帮助都将不胜感激 <tr *ngFor="let tag of locations"> <td align="center"><span style="font-size: 17px;" class="menu-icon icon-file-text2"></sp

所以我有个问题。我需要根据*ngFor循环中的动态数据计算tag.price的动态总计,以及小计和增值税。下面是我的html和ts代码。小计、合计和增值税值将在该块下方的循环之外。任何帮助都将不胜感激

 <tr *ngFor="let tag of locations">

 <td align="center"><span style="font-size: 17px;" class="menu-icon 
 icon-file-text2"></span></td>

 <td>{{tag.title}}</td>

 <th>{{tag.listingType}}</th>

 <th>{{ tag.size }}</th>

 <td>KSH {{tag.price | amount:locale}}</td>

 <td>KSH {{tag.price | amount:locale}}</td>

 </tr>


 // component ts
 setTags(id:any, title:any, price:any, listingType:any, size:any){
this.locations.push({
  title: title,
  id: id,
  price: price,
  listingType: listingType,
  size: size
});

{{tag.title}}
{{tag.listingType}
{{tag.size}}
KSH{{tag.price | amount:locale}
KSH{{tag.price | amount:locale}
//组件ts
setTags(id:any、title:any、price:any、listingType:any、size:any){
这个。位置。推({
标题:标题,,
id:id,
价格:价格,
listingType:listingType,
尺码:尺码
});

}

您可以在typescript中使用函数,也可以只绑定一个表达式

功能:

<div>
  {{ locationsSum() }}
</div>

public locationsSum() {
  return this.locations.map(tag => tag.price).reduce((a, b) => a + b, 0);
}

{{locationsSum()}}
公共场所{
返回这个.locations.map(tag=>tag.price).reduce((a,b)=>a+b,0);
}
表达方式:

<div>
  {{ locations.map(tag => tag.price).reduce((a, b) => a + b, 0) }}
</div>

{{locations.map(tag=>tag.price).reduce((a,b)=>a+b,0)}


我不确定你所说的“小计”和“增值税价值”是什么意思,但假设这些是基于价格的计算,概念应该是相同的



编辑:我最初发布的表达式选项不起作用。有关更多信息,请参阅。

您可以在typescript中使用函数,也可以只绑定一个表达式

功能:

<div>
  {{ locationsSum() }}
</div>

public locationsSum() {
  return this.locations.map(tag => tag.price).reduce((a, b) => a + b, 0);
}

{{locationsSum()}}
公共场所{
返回这个.locations.map(tag=>tag.price).reduce((a,b)=>a+b,0);
}
表达方式:

<div>
  {{ locations.map(tag => tag.price).reduce((a, b) => a + b, 0) }}
</div>

{{locations.map(tag=>tag.price).reduce((a,b)=>a+b,0)}


我不确定你所说的“小计”和“增值税价值”是什么意思,但假设这些是基于价格的计算,概念应该是相同的



编辑:我最初发布的表达式选项不起作用。有关更多信息,请参见。

我想您可以使用
#tag
然后使用
ViewChildren
创建forEach循环以获取值并对其进行计数。total是什么意思?您是指数组中所有tag price total的总和?我想您可以使用
tag
然后使用
ViewChildren
创建forEach循环以获取值然后数一数。你说的总数是什么意思?你指的是数组中所有标签价格总和的总和?