有条件地消除* ngFor中的列表项 - Angular 6 [重复]

问题描述 投票:0回答:1

这个问题在这里已有答案:

我正在尝试使用row-col div组合创建一个包含标签和值项的列表的4列表。问题是 - 我不想显示任何没有价值的列表项。不确定如何使用* ngFor和* ngIf实现(因为它们都不能在同一个元素上使用。任何帮助都会非常感激。这是我的代码示例

编辑:使用<ng-container>正确。更新的代码如下

<div class="container">

    <div class="row" *ngIf="myList && myList.length > 0">

        <ng-container *ngFor="let myField of myList">

            <div class="col-6" *ngIf="myField.udfDisplayValue">

                <div style="width: 50%; display: inline-block">
                    <b>{{ myField.fieldName }}</b>
                </div>

                <div style="width: 50%; display: inline-block;">
                    {{ myField.displayValue }}
                </div>

            </div>
        </ng-container>
    </div>
</div>
angular html5 twitter-bootstrap angular-ngfor
1个回答
0
投票

你可以使用[hidden]而不是* ngIf

© www.soinside.com 2019 - 2024. All rights reserved.