[英]How to display icon in mat-table row?
I use the mat-table and return an html data (an hyperlink) to this table and want to display icon or html on the related column's rows.我使用 mat-table 并将 html 数据(超链接)返回到该表,并希望在相关列的行上显示图标或 html。
<tr mat-row *matRowDef="let row; columns: displayedColumns"></tr>
But I am not sure how can I display it and how to distinguist if the related column is icon column.但是我不确定如何显示它以及如何区分相关列是否为图标列。 Because I do not get
tableColumn
peoperty in the row.因为我在行中没有得到
tableColumn
peoperty。 How can I do this?我怎样才能做到这一点?
Here is a DEMO and in this demo I just want to render this hyperlink below:这是一个演示,在这个演示中,我只想在下面呈现这个超链接:
const ELEMENT_DATA: PeriodicElement[] = [
{position: 1,
name: '<a href="http://www.google.com/search?q=Angular">Angular</a>', weight: 1.0079, symbol: 'H'},
{position: 2, name: 'Helium', weight: 4.0026, symbol: 'He'}
];
You can add mat-icon
in your mat-cell
and assign your html data to innerHTML
attribute.您可以在
mat-cell
添加mat-icon
并将您的 html 数据分配给innerHTML
属性。
<!-- Name Column -->
<ng-container matColumnDef="name">
<th mat-header-cell *matHeaderCellDef> Name </th>
<td mat-cell *matCellDef="let element">
<mat-icon [innerHTML]="element.name"></mat-icon> </td>
</ng-container>
Reference: https://stackblitz.com/edit/angular-8vpb5f?file=src/app/table-basic-example.html参考: https : //stackblitz.com/edit/angular-8vpb5f?file= src/ app/table-basic-example.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.