[英]How to add onClick event for rows on Angular Mat-Table then go to a different page?
My question is on how to add click event on a specific row and go to next form carrying the values of the clicked row. 我的问题是关于如何在特定行上添加click事件,并转到带有被单击行的值的下一个表单。 I'm a bit confused now 我现在有点困惑
<!-- Position Column -->
<ng-container matColumnDef="itemname">
<th mat-header-cell *matHeaderCellDef> ITEM NAME </th>
<td mat-cell *matCellDef="let element"> {{element.itemname}} </td>
</ng-container>
<!-- Name Column -->
<ng-container matColumnDef="category">
<th mat-header-cell *matHeaderCellDef> CATEGORY </th>
<td mat-cell *matCellDef="let element"> {{element.category}} </td>
</ng-container>
<!-- Weight Column -->
<ng-container matColumnDef="quantity">
<th mat-header-cell *matHeaderCellDef> QUANTITY </th>
<td mat-cell *matCellDef="let element"> {{element.quantity}} </td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
<tr class="rows" mat-row *matRowDef="let row; columns:
displayedColumns;">
</tr>
</table>
Try sending the value onClick like this. 尝试像这样发送onClick值。
<ng-container matColumnDef="itemname">
<th mat-header-cell *matHeaderCellDef> ITEM NAME </th>
<td mat-cell *matCellDef="let element">
<ng-container ng-click="passValue(element.itemname)">
{{element.itemname}}
</ng-container>
</td>
</ng-container>
And catch the value in js code as 并在js代码中捕获值
clickedValue:any;
passValue(val:any){
this.clickedValue = val;
console.log(clickedVal);
}
and then you can use the value , in any other form. 然后您可以使用其他任何形式的值。 Please ask for any clarification. 请要求任何澄清。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.