[英]How to get row data using angular material?
I have angular4 with materialize table Api so I am trying to get row data when user click on the row but its not passing data, How can i pass data to component from view any help will be appreciated ? 我有与实现表Api的angular4,所以当用户单击行但未传递数据时,我试图获取行数据,如何从视图中将数据传递给组件,将不胜感激?
app.component.html app.component.html
<div class="table-container">
<mat-table>
<ng-container matColumnDef="eventType">
<mat-header-cell *matHeaderCellDef> Event Type </mat-header-cell>
<mat-cell *matCellDef="let element"> {{element.eventType}} </mat-cell>
</ng-container>
<!--<button (click)="newMessage()" class="button">New Message</button>-->
<mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
<mat-row *matRowDef="let row; columns: displayedColumns;" (click)="highlight(row._id,$event)"></mat-row>
</mat-table>
</div>
app.component.ts app.component.ts
highlight(id,event){
console.log('Event',event);
}
Change to following in your template app.component.html
在模板app.component.html
更改为following
<mat-row *matRowDef="let row; columns: displayedColumns;" (click)="highlight(row,$event)"></mat-row>
and you should write your click handler in your component app.component.ts
您应该在组件app.component.ts
编写点击处理程序
highlight(row,evt) :void{
//console.log(row,evt);
}
Remove ._id from (click)="highlight(row._id,$event)" from your code. 从代码中的(click)=“ highlight(row._id,$ event)”中删除._id。 refer this 参考这个
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.