【发布时间】:2019-03-21 18:12:41
【问题描述】:
我正在尝试使表格上列中的单元格的值可编辑。问题是,由于表格是在 Angular 中使用来自 API 的值的 MatTableDataSource 动态生成的,因此单元格元素不能具有唯一的 ID。我怎样才能使它在模糊时(在编辑和更改单元格中的值之后)将该值传递给一个函数,然后该函数可以将该新值写入到 API 的请求中以更新它?
这是相关单元格列的 HTML:
<div>
<table mat-table matSort (matSortChange)="sortData($event)" [dataSource]="sortedData">
<!-- Other columns -->
<ng-container matColumnDef="maxInstalls">
<th mat-header-cell *matHeaderCellDef>Max Installs</th>
<td mat-cell *matCellDef="let profile">
<input type="number" min="0" value="{{profile.maximumInstalls}}"> <!-- I just need the value of this input -->
</td>
</ng-container>
<!-- Other columns -->
<tr mat-header-row *matHeaderRowDef="columnsToDisplay"></tr>
<tr mat-row *matRowDef="let row; columns: columnsToDisplay;">
</tr>
</table>
</div>
【问题讨论】: