【发布时间】:2019-02-19 08:04:05
【问题描述】:
我正在尝试根据 *ngIf 中提到的条件绑定值。当我在 *ngIf 中尝试 && 运算符时,它的工作原理很神秘。
代码
<div *ngIf="days.sunday == true">
<p class="circle ml-3">Sun</p>
</div>
<div *ngIf="days.monday == true">
<p class="circle ml-2">Mon</p>
</div>
<div *ngIf="days.tuesday == true">
<p class="circle ml-2">Tue</p>
</div>
<div *ngIf="days.wednesday == true">
<p class="circle ml-2">Wed</p>
</div>
<div *ngIf="days.thursday == true">
<p class="circle ml-2">Thu</p>
</div>
<div *ngIf="days.friday == true">
<p class="circle ml-2">Fri</p>
</div>
<div *ngIf="days.saturday == true">
<p class="circle ml-2">Sat</p>
</div>
上述条件工作正常。我可以相应地打印这些值。
<div *ngIf="days.sunday == true && days.monday == true && days.tuesday == true && days.wednesday == true &&
days.thursday == true && days.friday == true && days.saturday == true">
<p class="circle ml-2">Everyday</p>
</div>
根据上述条件,如果所有条件都为真,我正在尝试打印 Everyday,但我正在打印 sun mon tue wed thu fri sat Everyday
【问题讨论】:
-
那怎么了?如果一切都是
true,那么每个单独的检查也必须评估为true。 -
如果所有条件都为真,如何打印
Everything。我正在使用 && 运算符,但仍然 -
用你的代码做一个简单的演示:stackblitz.com
-
发布您的 component.ts 代码
标签: angular typescript