我正在尝试使表格中的列中的单元格的值可编辑。问题是,由于表是使用Angular中的MatTableDataSource与API中的值动态生成的,因此单元格元素不能具有唯一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>
关于什么
<input type="number" min="0" value="{{profile.maximumInstalls}}" (blur)="onBlu(profile)">
如果你想要输入的值你需要创建一个输入的引用并使用它如下所示
<input #valueInput type="number" min="0" value="{{profile.maximumInstalls}}" (blur)="onBlur(valueInput.value)">
看到工作示例here