如何合并ngif标准

时间:2019-05-26 16:13:37

标签: angular angular-ng-if

我试图仅在符合image.media_type === image的条件下显示数据。如何在ngfor中添加它,以便仅显示图像?

<div *ngFor="let image of childPhotos">

    <div class="gallery openImageDialog" data-id={{image.url}} data-title={{image.title}}>
      <span id="myExplan" data-id={{image.explanation}}></span>
      <a href="#gardenImage" class="thumbnail" data-toggle="modal">
        <img class="img-responsive" src={{image.url}} alt={{image.title}}>
        <div class="hidden" data-title={{image.title}}></div>
      </a>
      <div class="desc">{{image.title}}</div>
    </div>

</div>

1 个答案:

答案 0 :(得分:2)

当然,您可以在div的ngFor循环之后添加它

<div *ngFor="let image of childPhotos">
    <div *ngIf="image.media_type === 'image'" class="gallery openImageDialog" data-id={{image.url}} data-title={{image.title}}>
      <span id="myExplan" data-id={{image.explanation}}></span>
      <a href="#gardenImage" class="thumbnail" data-toggle="modal">
        <img class="img-responsive" src={{image.url}} alt={{image.title}}>
        <div class="hidden" data-title={{image.title}}></div>
      </a>
      <div class="desc">{{image.title}}</div>
    </div>
</div>