angular 4: *ngIf with multiple conditions

天涯浪子 提交于 2021-01-20 16:17:41

问题


I'm confused a bit. I need to hide block if result have one of several cases. But seems it not working correctly...

<div *ngIf="currentStatus !== 'open' || currentStatus !== 'reopen' ">

    <p padding text-center class="text-notification">{{message}}</p>

</div>

It's just appeared with other condition. It doesn't work neither 1 condition nor for 2. Also tried *ngIf="currentStatus !== ('open' || 'reopen') " but it's works ok only for 1 case.


回答1:


Besides the redundant ) this expression will always be true because currentStatus will always match one of these two conditions:

currentStatus !== 'open' || currentStatus !== 'reopen'

perhaps you mean one of

!(currentStatus === 'open' || currentStatus === 'reopen')
(currentStatus !== 'open' && currentStatus !== 'reopen')



回答2:


You got a ninja ')'.

Try :

<div *ngIf="currentStatus !== 'open' || currentStatus !== 'reopen'">



回答3:


<div *ngIf="currentStatus !== ('status1' || 'status2' || 'status3' || 'status4')">


来源:https://stackoverflow.com/questions/43801823/angular-4-ngif-with-multiple-conditions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!