【发布时间】:2019-10-28 12:00:39
【问题描述】:
我正在尝试根据我的 Angular 7 应用程序中的行中的 <td> 值隐藏和显示。在下面的示例中,三行具有以下标题。
组件
public ColumnNames: string[] = ['Legal Class Name', 'Last Edited' , 'Legal Class ID'];
如果您在代码中注意到,我试图根据以下条件隐藏一行。我正在寻找的是应该根据上次编辑行中的值隐藏该行。因此,如果 Last Edited 中的值为 true,我需要显示 ColumnNames[2]
<ng-container *ngIf="c != ColumnNames[2]">
HTML
<table class="fundClassesTable table-striped" border="1">
<tr *ngFor="let c of ColumnNames">
<ng-container *ngIf="c != ColumnNames[2]">
<th class="tableItem bold">{{ c }}</th>
<ng-container *ngFor="let f of data">
<ng-container>
<td class="tableItem" *ngIf="c == ColumnNames[0]">{{f.Description}}</td>
<td class="tableItem" *ngIf="c == ColumnNames[1]">{{f.AuditSummary}}</td>
<td class="tableItem" *ngIf="c == ColumnNames[2]">{{f.Id}}</td>
</ng-container>
</ng-container>
</ng-container>
</tr>
</table>
更新截图
【问题讨论】:
-
HTML:在
*ngIf中调用一个函数,将行的索引传递给它... TS:检查上一个索引以了解您的情况并通过真/假; -
我不太清楚你的意思。我创建了一个 jsfiddle jsfiddle.net/nc8kjofr/1。你能告诉我吗
-
理想的结果应该是?
-
不要在这里说模棱两可的行/列造成混淆,如果
Last Edited即AuditSummary为真,您是否要隐藏Class X? Like this? -
@Tom 如果最后编辑的任何一个为真,您想隐藏整行的合法类 ID
标签: html angular typescript html-table angular-ng-if