是否可以将没有ID的Angular生成的输入值传递给函数?

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

我正在尝试使表格中的列中的单元格的值可编辑。问题是,由于表是使用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>
angular input id
1个回答
0
投票

关于什么

<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

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