事实上,可以在没有数据源的情况下创建材质表。
您需要确保使用显示的列和所有列创建了标题定义。
示例-html文件:
<table mat-table class="mat-elevation-z8">
<ng-container matColumnDef="someValue">
<th mat-header-cell *matHeaderCellDef mat-sort-header>Some Value Header</th>
</ng-container>
<ng-container matColumnDef="someOtherValue">
<th mat-header-cell *matHeaderCellDef mat-sort-header>
Some Other Value Header
</th>
</ng-container>
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
<tr mat-row *matRowDef="let row; columns: displayedColumns"></tr>
</table>
在ts文件中,需要定义数组
displayedColumns: string[] = ['someValue', 'someOtherValue'];
编辑:
如果您的需求只是一个带有几个预定义值的简单表格,那么您可以通过使用带有材质css类的本机表格元素来实现:
<table class="mat-table" >
<tr class="mat-header-row">
<th class="mat-header-cell">A</th>
<th class="mat-header-cell">B</th>
</tr>
<tr class="mat-row">
<td class="mat-cell">A</td>
<td class="mat-cell">B</td>
</tr>
</table>