首页 > 解决方案 > 使用带有“||”的异步管道 操作员无法正常工作

问题描述

我想使用带有“||”的异步管道 运营商,但我不知道如何。例如:

<div class="col-md-12" *ngIf="(someSubscription$ | async) as users || someCondition">

标签: angularasync-pipe

解决方案


您可以使用括号来组合异步管道的输出和条件。

*ngIf="(someSubscription$ | async) || someCondition as output"

假设这someSubscription$不是Observable<boolean>,那么您可以执行严格的测试来区分output

<div *ngIf="(someSubscription$ | async) || someCondition as output">
  <div *ngIf="output === true else other">
    output from someSubscription$ must be falsy
  </div>
  <ng-template #other>
    {{output.name}}
  </ng-template>
</div>

演示:https ://stackblitz.com/edit/angular-zxzg9v


推荐阅读