下面的脚本显示了使用的购物车ng-repeat.对于数组中的每个元素,它显示项目名称,其数量和小计(product.price * product.quantity).
计算重复元素总价的最简单方法是什么?
<table>
<tr>
<th>Product</th>
<th>Quantity</th>
<th>Price</th>
</tr>
<tr ng-repeat="product in cart.products">
<td>{{product.name}}</td>
<td>{{product.quantity}}</td>
<td>{{product.price * product.quantity}} €</td>
</tr>
<tr>
<td></td>
<td>Total :</td>
<td></td> <!-- Here is the total value of my cart -->
</tr>
</table>
Run Code Online (Sandbox Code Playgroud)