【发布时间】:2018-03-07 11:39:44
【问题描述】:
我有这个数据,
[Products, Products, Products, Products]
0: Products {product_id: "1", Product_type_id: "11", Subtotal:450, …}
1: Products {product_id: "2", Product_type_id: "22", Subtotal:550, …}
2: Products {product_id: "3", Product_type_id: "33", Subtotal:600, …}
3: Products {product_id: "4", Product_type_id: "44", Subtotal:100, …}
我想sum(Subtotal) 使用这个功能,但在 html 中什么也不显示
products: Products[] = [];
public cartTotal(): number {
let total: number = 0;
this.products.forEach((e: any) => {
total = total + Number(e.subtotal);
});
return total;
}
html代码:
<label for="total">Totale: {{total}} </label> --> show nothing
<label for="total">{{cartTotal(total)}}Totale: ALL</label> --> show NaN
【问题讨论】:
-
您的数据显示
Subtotal,但您的代码显示subtotal这只是问题中的拼写错误,还是实际问题?
标签: html angular typescript calculator