angular - 设置材料表中数组属性中的值
问题描述
我正在创建一个材料表。数据源的元素具有数组属性。我想在表格的每一列中显示该属性中成员的值,如下面的代码。但是,没有显示任何内容。我哪里弄错了?
注意:我用来创建多列的 ng-container 中的 ngFor。
<ng-container *ngFor="let vendor of vendors" [matColumnDef]="vendor.Name">
<mat-header-cell *matHeaderCellDef>{{vendor.Name}}</mat-header-cell>
<mat-cell *matCellDef="let element">
<span *ngIf="element.Type == 2 else textValue">
<span *ngFor="let cost of element.Cost">
{{cost}}
</span>
</span>
<ng-template #textValue>
<span *ngFor="let textValue of element.TextValue">
{{textValue}}
</span>
</ng-template>
</mat-cell>
</ng-container>
解决方案
尝试使用th
和td
元素如下:
<ng-container *ngFor="let vendor of vendors" [matColumnDef]="vendor.Name">
<th mat-header-cell *matHeaderCellDef>{{vendor.Name}}</th>
<td mat-cell *matCellDef="let element">
<span *ngIf="element.Type == 2 else textValue">
<span *ngFor="let cost of element.Cost">
{{cost}}
</span>
</span>
<ng-template #textValue>
<span *ngFor="let textValue of element.TextValue">
{{textValue}}
</span>
</ng-template>
</td>
</ng-container>
推荐阅读
- boost - Boost Libraries 在 Linux 上调试和发布构建
- r - How to change date value in R?
- arrays - 在 Mongodb 和 EJS 中使用数组
- orbeon - Orbeon 表单中的批量更新权限
- c# - 如何使两个数组中的元素成为条件,Linq c#
- mp4 - AAC 音频文件播放速度比正常速度快
- html - 如何使我的网站具有响应性 - 表格文本相互重叠
- java - 如何重写 document.getElementsByTagName(); 与 XPath?
- javascript - 如何修复我的项目中未加载图像和 CSS 的问题?
- php - Cakephp 3.6.14:创建带有复选框和处理数据的表格