【问题标题】:Angular 2 - Hide Panel with table when table is emptyAngular 2 - 当表格为空时隐藏带有表格的面板
【发布时间】:2016-11-07 16:31:16
【问题描述】:

我有一个 *ngFor 来创建包含表格的面板。这些表有一个 *ngFor,它为数据集中的每个项目创建 <td>

有时该表会有空行。有没有一种聪明的方法来使用 Angular 隐藏没有子表的面板?我可能可以使用 jQuery 来检查加载中的孩子,但我觉得使用 Angular *ngFor 应该有一个更直观的答案。

<div class="col-md-12 col-lg-6 cell-box" *ngFor="let siteGroup of sqlData | FilterData:[currentDate, selectedGroup] | UniqueValue:['Site']">

                <!-- SD Data -->
                <div class="panel panel-midblue">
                    <div class="panel-heading">
                        <span>{{selectedGroup}} - {{siteGroup}}</span>
                    </div>
                    <div class="panel-body">
                        <table class="exportTable table table-hover table-condensed">
                            <thead>
                                <th>Metric Name</th>
                                <th>Daily&emsp;&emsp;&emsp;</th>
                                <th>Week to Date</th>
                                <th>Month to Date</th>
                                <th>Year to Date</th>
                            </thead>
                            <tr *ngFor="let item of sqlData | FilterData:[currentDate, selectedGroup, siteGroup, selectedType] | OrderBy:['MetricName',['Volume','TSF', 'ASA','AHT', 'ACW', 'ABAN', 'FCR']]" [attr.goalvalue]="item.DayMetGoal">
                                <td>{{item.MetricName}}</td>
                                <td class="cursor-hand" [attr.goalvalue]="item.DayMetGoal" (click)="ModalPopUp($event, item)">{{item.DayMetricValue | FormatMetric:item.MetricName }}</td>
                                <td class="cursor-hand" [attr.goalvalue]="item.WTDMetGoal" (click)="ModalPopUp($event, item)">{{item.WTDMetricValue | FormatMetric:item.MetricName }}</td>
                                <td class="cursor-hand" [attr.goalvalue]="item.MTDMetGoal" (click)="ModalPopUp($event, item)">{{item.MTDMetricValue | FormatMetric:item.MetricName }}</td>
                                <td class="cursor-hand" [attr.goalvalue]="item.YTDMetGoal" (click)="ModalPopUp($event, item)">{{item.YTDMetricValue | FormatMetric:item.MetricName }}</td>
                            </tr>
                        </table>
                    </div>
                    <div class="panel-footer">
                        <h5 class="text-muted"></h5>
                    </div>
                </div>

            </div>

【问题讨论】:

    标签: angular ngfor


    【解决方案1】:

    你可以使用[隐藏]

    <h3 [hidden]="!favoriteHero">
      Your favorite hero is: {{favoriteHero}}
    </h3>
    

    查看角度文档: https://angular.io/docs/ts/latest/cookbook/a1-a2-quick-reference.html#!#ng-show

    【讨论】:

    • 感谢您指出用于在 Angular 2 中隐藏的方法。根据提供的代码,我将如何设置可用于检查的变量。我基本上需要说,如果“项目”没有价值,那么隐藏父面板。
    • @Tekk_Know 是 sqlData 对象数组吗?如果是这样,你可以这样做 [hidden]="sqlData.length == 0"
    • sqlData 确实是一个对象数组。你知道做 sqlData.length 是否会做过滤管道应用后的长度吗?
    • @Tekk_Know 老实说,我不确定我以前没有这样做过。我的假设是没有。试试看?
    猜你喜欢
    • 2014-01-23
    • 2019-09-25
    • 1970-01-01
    • 2012-03-24
    • 1970-01-01
    • 1970-01-01
    • 2012-08-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多