2017-05-05 90 views
2

我有點困惑。如果結果有幾種情況之一,我需要隱藏塊。但似乎它不能正常工作...角度4:* ngIf與多重條件

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

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

</div> 

它剛剛出現與其他條件。它不適用於1條件也不適用於2.也嘗試*ngIf="currentStatus !== ('open' || 'reopen') ",但它只適用於1個案例。

+0

預期的行爲是什麼?何時應評估爲「真」,何時評估爲「假」?示例中出現 –

回答

10

除了冗餘)這個表達式永遠是true因爲currentStatus將始終與這兩個條件之一:

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

也許你的意思的

!(currentStatus === 'open' || currentStatus === 'reopen') 
(currentStatus !== 'open' && currentStatus !== 'reopen') 
一個
+0

那麼根據什麼狀態,預期的行爲是什麼? –

+2

第二個例子工作正常。謝謝! –

+1

@合併小馬似乎你使用OR而不是AND,因爲'!(currentStatus ==='open'|| currentStatus ==='reopen')'給出與'currentStatus!=='打開'相同的結果' && currentStatus!=='reopen'' – mankers

1

你有一個忍者')'。

嘗試:

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

錯誤。我的錯。在原始代碼結果中詢問 –