我想在我的表格中对这些数字进行求和:
我需要制作过滤器还是需要 ngFor 吗? 我知道这样的计算没有意义。 我试过:
<th>
<i>Sum:{{ this.invoices?.sum | number }}</i>
</th>
ts:
calcSum = ( invoice: any): string => {
if ( !invoice) {
return '0';
}
return (this.invoices.sum + this.invoices.sum );
}
界面:
export interface InvoiceResponse{
paid: boolean,
paidAmount: number,
client: string,
number: number,
total:number,
taxTotal: number,
sum: number,
currencyRate: string,
currencyRateAtIssueDate: string,
issuedAtPlace: string,
issuedAt: string,
deadlineAt: string
}
myArray.map((i) => i.myProperty).reduce((a, b) => a + b);
ts
calcSum = this.invoices.map((i) => i.sum).reduce((a, b) => a + b);
html
<th>
<i>Sum:{{ calcSum }}</i>
</th>
更多信息和一些示例可以在以下文章中找到: