2017-07-27 24 views
-1

我有一個使用Angular Material的消息應用程序。我希望程序檢查未讀消息的數量是否等於0,以隱藏顯示未讀消息數量的span元素。如何根據Javascript變量隱藏span元素?角材

topbar.html:

<span class="button_badge" id="button_badge">{{notifications}}</span>

{{notifications}}可變來自一個JavaScript控制器。當通知== 0隱藏元素時,如何讓程序檢查?

+3

您可以使用ng-hide =「notifications == 0」我相信 – DDelgro

回答

1

有幾種方法可以與AngularJs做到這一點。

  1. 使用NG隱藏或NG-顯示: <span class="button_badge" id="button_badge" ng-hide="notifications == 0">{{notifications}}</span>

  2. 使用NG-IF:<span class="button_badge" id="button_badge" ng-if="notifications != 0">{{notifications}}</span>

希望這可以幫助你!