[英]Angular directive not working with ng-container
The given below code ng-if is not working as expected下面给出的代码 ng-if 没有按预期工作
if displayGroup
value is D
then it will print the first and Second block, did I made any mistake如果displayGroup
值为D
那么它会打印第一个和第二个块,我有没有弄错
<div *ngIf="(bookTravelInfo.displayGroup | uppercase) === 'A' || 'B' || 'C' ">
<h2>Perfect!</h2>
</div>
<div *ngIf="(bookTravelInfo.displayGroup | uppercase) === 'D' ">
<h2>Does not Perfect</h2>
</div>
If you want to check bookTravelInfo.displayGroup
is either 'A' or 'B' or 'C',如果你想检查bookTravelInfo.displayGroup
是'A'或'B'或'C',
Use利用
*ngIf="['A', 'B', 'C'].includes(bookTravelInfo.displayGroup | uppercase)"
||
Logical OR operator from your *ngIf
will never return false
. *ngIf
中的逻辑 OR 运算符永远不会返回false
。
As the boolean result returned true
when the value is neither null
, nor undefined
nor false
as according to ToBoolean .由于 boolean 结果返回true
当值既不是null
,也不是undefined
或false
根据ToBoolean 。
Hence the first <div>
element still be displayed with:因此第一个<div>
元素仍然显示为:
*ngIf="(bookTravelInfo.displayGroup | uppercase) === 'A' || 'B' || 'C'"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.