【发布时间】:2019-12-30 04:50:53
【问题描述】:
我创建了一个 HTML 表格,它将根据 输入数据中的行数。我尝试以this SO post 为例,但我正在努力将我的 HTML 转换为 Angular Material 设计。有什么建议吗?
由于 Angular 材质表是基于列的(而且我找不到迭代其中的行的方法)我很快就卡住了。
我无法在 StackBlitz 中获得角度材料表,所以这里是我的代码的复制粘贴:
<table mat-table [dataSource]="newLicenseDS">
<ng-container *ngFor="let disCol of newLicCol; let idx = index" matColumnDef="{{disCol}}">
<th mat-header-cell *matHeaderCellDef>{{disCol}}</th>
<ng-container *ngIf="idx==0">
<td mat-cell *matCellDef="let e">{{e[0]|json}}</td>
</ng-container>
<ng-container *ngIf="idx==1">
<td mat-cell *matCellDef="let e">{{e[1]|json}}</td>
</ng-container>
<ng-container *ngIf="idx==2">
<td mat-cell *matCellDef="let e[2]">{{e|json}}</td>
</ng-container>
</ng-container>
<tr mat-header-row *matHeaderRowDef="newLicCol"></tr>
<tr mat-row *matRowDef="let row; columns: newLicCol"></tr>
</table>
【问题讨论】:
-
为什么?这有什么真正的原因吗?性能会咬你。
-
不一定是无限的,但是我不能提前知道会有多少列,可能远少于一百列,但我不能保证,哪个这就是我为什么要这样写的原因
标签: angular angular-material mat-table