2017-02-12 65 views
2

我寫了一個名爲wordsAllDone的點來檢查是否所有的單詞都標記爲done,它的輸出是一個布爾值。 但是,我想讓這個按鈕隱藏,當words | wordsAllDonetrue並顯示它的時候是false可以在angular2模板中使用管道(|)使用'=='嗎?

<button *ngIf="words | wordsAllDone == false" (click)="startReview()">START</button> 

但angular2顯示解析錯誤:

<button [ERROR ->]*ngIf="words | wordsAllDone == false" (click)="startReview()" ion-button item-right outline>START</button>:[email protected]:20 
Parser Error: Unexpected token ==, expected identifier, keyword, or string at column 22 in [words | wordsAllDone == false] in [email protected]:20 

我可以使用==運營商與|在同一時間?

+0

您是否嘗試使用圓括號來闡明您想要的內容 - '(words | wordsAllDone)== false'? – jonrsharpe

+0

工作正常!非常感謝。 @jonrsharpe – awmleer

+0

@jonrsharpe如果您將此添加爲答案awmleer可以接受它,問題將顯示爲已回答。 –

回答

2

您需要添加括號明確指出要返回值從管道比較:

*ngIf="(words | wordsAllDone) == false" 

注意你也可以使用!而不是false比較平等:

*ngIf="!(words | wordsAllDone)" 
相關問題