angular ng-content 不反映动态内容

时间:2021-01-23 16:57:12

标签: angular angular-cdk angular2-ngcontent

我一直在使用 cdk 表功能创建自定义数据表组件。行和标题定义应该在组件之外。因此,我在表中放置了一个 ng-content 标签,并尝试从组件外输入标题和行以反映在那里。然而,表内没有反映任何内容。我想它不适用于 ng-container,但如果有人能指出我正确的方向,那么应该为这个用例使用什么。 这是片段。

simple-table.html

<table cdk-table [dataSource]="dataSource">
  <ng-content></ng-content>
</table>

app.component.html

<simple-table [dataSource]="dataSource">
  <ng-container cdkColumnDef="username">
    <th cdk-header-cell class="table-header" *cdkHeaderCellDef> User name </th>
    <td cdk-cell *cdkCellDef="let row" class="cell-text"> {{row.id}} </td>
  </ng-container>

  <ng-container cdkColumnDef="age">
    <th cdk-header-cell class="table-header" *cdkHeaderCellDef> Age </th>
    <td cdk-cell *cdkCellDef="let row" class="cell-text">{{row.status}}</td>
  </ng-container>

  <tr cdk-header-row *cdkHeaderRowDef="['username', 'age']"></tr>
  <tr cdk-row *cdkRowDef="let row; columns: ['username', 'age']"></tr>
</simple-table>

0 个答案:

没有答案
相关问题