*ngIf 中的角度异步管道 - 处理 0 值

use*_*344 4 asynchronous angular

我有以下 html 片段:

<div *ngIf="calculatedValue$ | async as calculatedValue">
  {{calculatedValue}}
</div>
Run Code Online (Sandbox Code Playgroud)

但如果计算值 $ 的发出值为 0(类型 = 数字),则该 div 将不会显示在 DOM 中。

正确的展示方式是什么?也许是通过将非空检查添加到 *ngIf 的方式。

Lau*_*enz 5

如何在注释中提及@joosep部分,您可以将值分配给对象,例如此代码即使其值为0也显示进度条

组件.ts

progress$ = new BehaviorSubject<number>(0);
Run Code Online (Sandbox Code Playgroud)

组件.html

<ng-container *ngIf="{ value: progress$ | async } as progress">
    <app-progressBar
       [value]="progress.value"
    ></app-progressBar>
</ng-container>
Run Code Online (Sandbox Code Playgroud)