我使用的是Angular 9。我如何构造一个没有标题行(th)的mat- table?听起来很傻,但如果我这么做
<table mat-table *ngIf="isMobile" #mobile_table [dataSource]="dataSource">
<ng-container matColumnDef="item">
<td mat-cell *matCellDef="let item_stat">
<div class="smallHeading">
{{ item_stat.max_date }} m
</div>
<div class="mainRow divider">
<a href="{{ item_stat.mobile_path }}">{{ item_stat.title }}</a> ·
{{ getScore(item_stat) }}
</div>
</td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="mobileDisplayedColumns"></tr>
<tr mat-row *matRowDef="let row; columns: mobileDisplayedColumns;" [ngClass]="getRowClass(row)"></tr>
</table>它会产生错误
ERROR TypeError: Cannot read property 'template' of undefined
at MatHeaderRowDef.extractCellTemplate (table.js:567)
at table.js:2522
at Function.from (<anonymous>)
at MatTable._getCellTemplates (table.js:2512)
at MatTable._renderRow (table.js:2467)
at table.js:2326
at Array.forEach (<anonymous>)
at MatTable._forceRenderHeaderRows (table.js:2321)
at MatTable.ngAfterContentChecked (table.js:1800)
at callHook (core.js:4730)我必须补充一点
<th mat-header-cell *matHeaderCellDef></th>以使表正确呈现。这似乎没有必要,因为我不想让我的表有一个标题行。我如何构建我的mat-table,以使这不是必需的?
发布于 2021-05-20 11:00:19
你只需要删除标题行mat- header -row *我就可以了。
发布于 2021-10-02 18:20:28
只需删除此行:
<tr mat-header-row *matHeaderRowDef="mobileDisplayedColumns"></tr>发布于 2021-10-30 13:39:45
两种方式
删除<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
或
在css组件上添加:host ::ng-deep thead{display: none;}
https://stackoverflow.com/questions/67062128
复制相似问题