44

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.

Cœur
  • 32,421
  • 21
  • 173
  • 232
Merge-pony
  • 1,272
  • 2
  • 13
  • 29

3 Answers3

69

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')
Günter Zöchbauer
  • 490,478
  • 163
  • 1,733
  • 1,404
  • 1
    So what is the expected behavior depending on what status? – Günter Zöchbauer May 05 '17 at 09:58
  • 1
    @Merge-pony It seems that you use OR instead of AND, because `!(currentStatus === 'open' || currentStatus === 'reopen')` gives the same result as `currentStatus !== 'open' && currentStatus !== 'reopen'` – mankers May 05 '17 at 10:05
  • @mankers yes, it is!!! But it doesn't work. I'm using Ionic 3 and Angular 4 stack... – Merge-pony May 05 '17 at 10:37
14

You got a ninja ')'.

Try :

<div *ngIf="currentStatus !== 'open' || currentStatus !== 'reopen'">
Toodoo
  • 6,992
  • 4
  • 29
  • 52
3
<div *ngIf="currentStatus !== ('status1' || 'status2' || 'status3' || 'status4')">
Adithya421
  • 69
  • 5
  • 1
    How on earth does it have 4 upvotes? `('status1' || 'status2' || 'status3' || 'status4')` is just `'status1'`. – Tortila Apr 10 '21 at 08:16