如何对表格角度中的数字求和

问题描述 投票:0回答:1

我想在我的表格中对这些数字进行求和:

我需要制作过滤器还是需要 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

}

angular typescript html-table sum calculated-columns
1个回答
0
投票
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>

更多信息和一些示例可以在以下文章中找到:

© www.soinside.com 2019 - 2024. All rights reserved.