angular中第三列(同一行)计算并显示的两个不同列的输入值的总和

Summation of input values of two different columns calculated and displayed in the third column (same row) in angular

我想计算两个不同列的输入总和,并在第三列显示总和。在 angular material table 中使用 ngmodel 和模板驱动表单。下面是格式

1st 2nd total
4 5 9

您可以通过访问 *matCellDef 中的 row 而不是 element 并调用方法来计算总数来实现此目的。

<ng-container matColumnDef="total">
    <th mat-header-cell *matHeaderCellDef>Total</th>
    <td mat-cell *matCellDef="let row">{{getTotal(row)}}</td>
</ng-container>

在ts文件中:

getTotal(row) {
     return row.first + row.second;
  }

查看工作示例here

现在已修复:

getTotal(row:any) {
   return (parseInt(row.first) + parseInt(row.second));
   }