小编I.H*_*ann的帖子

向 Angular Material Table 中的 MatCell 添加自定义多行 HTML 内容

我想在表格单元格中添加不同样式的多行。不过,Angular Material 表似乎剥离了我的 HTML 代码。我怎样才能在Gitlab中实现类似的东西,其中一行/项目内的第一行(例如“管理员”)的样式与第二行(例如电子邮件地址)的样式不同,如代码示例所示。

表格组件.html

<ng-container matColumnDef="name">
   <mat-header-cell *matHeaderCellDef>{{header}}</mat-header-cell>
   <mat-cell *matCellDef="let row">

      <!-- first approach -->
      <div class="firstline">{{row.firstline}}</div>
      <div class="secondline">{{row.secondline}}</div>

      <!-- second approach -->
      <multiline-component [firstline]="row.firstline" [secondline]="row.secondline"></multiline-component>

   </mat-cell>
</ng-container>

Run Code Online (Sandbox Code Playgroud)

多行组件.html

<div class="firstline">{{firstline}}</div> // I want to be bold
<div class="secondline">{{secondline}}</div> // I want to be just regular
Run Code Online (Sandbox Code Playgroud)

我尝试将 [innerHTML] 与 bypassSecurityTrustHtml()-Pipe 一起使用,以防止剥离失败。我还尝试使用具有 [firstline] 和 [secondline] 属性绑定的自定义组件。

angular-material angular mat-table

5
推荐指数
1
解决办法
4493
查看次数

标签 统计

angular ×1

angular-material ×1

mat-table ×1