Cha*_* L. 2 angular-ui-router angular-material angular-material2 angular6
我有一个数据表,我正在尝试分配<a>一个参与者名称<td>,该名称将在单击新组件时将用户带入。
<ng-container matColumnDef="name">
<th mat-header-cell *matHeaderCellDef> Name </th>
<td mat-cell *matCellDef="let Participant"> <a routerlink="/participants/userId">{{Participant.name}}</a> </td>
</ng-container>
Run Code Online (Sandbox Code Playgroud)
它没有显示错误或其他任何内容,但是,它没有使<td>clickable可用,它完全忽略了routerLink,如果我将分配href给<a>它的话。
小智 5
一种解决方法是基于(单击)事件。
<ng-container matColumnDef="name">
<th mat-header-cell *matHeaderCellDef> Name </th>
<td mat-cell *matCellDef="let Participant">
<span style="cusor:pointer;" (click)="navigate(Participant)">
{{Participant.name}}</span> </td>
</ng-container>
Run Code Online (Sandbox Code Playgroud)
在您的打字稿代码中:
private navigate(product){
this.router.navigate(['/participants', product]); //we can send product object as route param
}
Run Code Online (Sandbox Code Playgroud)
谢谢。