角度 4:*ngIf 具有多个条件 [英] angular 4: *ngIf with multiple conditions

查看:34
本文介绍了角度 4:*ngIf 具有多个条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有点困惑.如果结果有几种情况之一,我需要隐藏块.但似乎它不能正常工作...

<div *ngIf="currentStatus !== 'open' || currentStatus !== 'reopen' "><p padding text-center class="text-notification">{{message}}</p>

它只是在其他情况下出现.它既不适用于 1 种情况,也不适用于 2 种情况.也尝试过 *ngIf="currentStatus !== ('open' || 'reopen') " 但它仅适用于 1 种情况.

解决方案

除了多余的 ) 这个表达式总是 true 因为 currentStatus将始终匹配以下两个条件之一:

currentStatus !== 'open' ||currentStatus !== '重新打开'

也许你的意思是其中之一

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

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.

解决方案

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')

这篇关于角度 4:*ngIf 具有多个条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆