Estoy usando Angular 9. ¿Cómo construyo una tabla mat sin una fila de encabezado (th) para la tabla? Suena tonto, pero si hago esto
<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>
me produce el error
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)
debo agregar
<th mat-header-cell *matHeaderCellDef></th>
para que la tabla se renderice correctamente. Esto parece innecesario ya que no quiero una fila de encabezado para mi tabla. ¿Cómo construyo mi tapete para que no sea necesario?
Solución del problema
Solo necesita eliminar la línea de encabezado mat-header-row * <tr mat-header-row matHeaderRowDef="mobileDisplayedColumns">
A mí me funciona bien.
No hay comentarios.:
Publicar un comentario