【发布时间】:2021-05-25 19:10:27
【问题描述】:
html 正在打印表中的所有 API 数据。产品和组件 当组件为空时,表格不应打印产品。做这个的最好方式是什么? 我正在使用角度 8
产品 = { “身份证”:1, “姓名”:“约翰”, “组件”: [ { “身份证”:130, “名称”:“价格”, } ] "isSelected": false }
产品 = { “身份证”:2, “名称”:“名称”, “组件”:[] }
<div class="card">
<div class="card-body">
<table class="table table-striped table-bordered hover">
<thead>
<tr>
<th width="1%" class="text-center"></th>
<th width="8%" class="text-center">Id</th>
<th width="8%" class="text-center">Name</th>
</tr>
</thead>
<tbody>
<ng-container *ngFor="let product of products; index as i">
<tr>
<td>
<div>
<button class="btn btn-sm btn-default"></button>
</div>
</td>
<td>{{product.id}}</td>
<td>{{product.name}}</td>
</tr>
<tr *ngFor="let prodComp of product.components">
<td></td>
<td>{{prodComp.id}}</td>
<td>{{prodComp.name}}</td>
</tr>
</ng-container>
</tbody>
</table>
</div>
</div>
【问题讨论】:
-
<table *ngIf="product;else noData"></table><ng-template #noData>Hey, there's no data for the table</ng-template>干杯 -
@robbieAreBest 你能举例说明如何在 TS 上过滤吗?