Angular NgIf和zero:为什么不呈现模板?
我有以下可观察的平面和角度分量:Angular NgIf和zero:为什么不呈现模板?,angular,angular-ng-if,angular-template,Angular,Angular Ng If,Angular Template,我有以下可观察的平面和角度分量: count$: Observable<number>; this.count$ = this.getCount(); 在模板上,我有: <a routerLink="/dash" *ngIf="(count$ | async)"> <ng-container *ngIf="count$ | async as count"> Count: {{count}} </ng-container> <
count$: Observable<number>;
this.count$ = this.getCount();
在模板上,我有:
<a routerLink="/dash" *ngIf="(count$ | async)">
<ng-container *ngIf="count$ | async as count">
Count: {{count}}
</ng-container>
</a>
计数:{{Count}
如果count$
为1,我得到count:1
,但如果count$
为0,则内容count:0
甚至不会呈现
知道为什么吗?您使用的是ngIf,这意味着您正在有条件地显示您的值。当值为0时,您的条件计算为false,因此不会显示。如中所述,这是预期的行为
NgIf
将给定表达式强制为布尔值。如果表达式的计算结果为值(转换为false的值),则不会呈现内容
以下是javascript当前转换为false的所有值:
我不知道。谢谢你的提示。
<a routerLink="/dash" *ngIf="(count$ | async)">
<ng-container *ngIf="count$ | async as count">
Count: {{count}}
</ng-container>
</a>
if (false)
if (null)
if (undefined)
if (0)
if (NaN)
if ('')
if ("")
if (``)