我正在使用 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>
使表格正确呈现。这似乎没有必要,因为我不希望我的表格有标题行。我如何构建我的垫子 table ,以便这不是必需的?
最佳答案
您只需要删除标题行 mat-header-row
*
它对我来说很好用。
关于angular - 如何渲染没有标题行的 Angular 9 mat-table?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67062128/
上一篇:qt - Qt Creator 构建和运行设置存储在哪里?
下一篇:reactjs - 当我点击 yarn run dev 。它显示 'next' 不是内部或外部命令,也不是可运行的程序或批处理文件
相关文章:
angular - 监听 Angular 9 Reactive 表单中 2 个依赖字段的变化
带有 jsPDF 模块 : Type 'typeof jsPDF' has no construct signatures 的 Angular 9
angular - Angular2 组件中的单元测试 RouterLink
Angular6 Jasmine TypeError : expect(. ..).toBeVisible 不是一个函数
css - Bootstrap Angular 日期选择器 ngbDatepicker 不会在 ngbPanelContent 上溢出
angular - 如何在 Angular2 中根据特定的构建环境注入(inject)不同的服务?
jquerysiblings() 获取 previous sibling 而不是下一个