簡體   English   中英

如果其他條件在帶有“或”的角度html標簽中

[英]if else condition in angular html tag with “or”

我必須在html中顯示元素的數量,我希望它在n> 1或n = 0時顯示“ n名學生參加”,而只有一個學生時顯示“ n名學生參加”:n = 1個學生。所以我在html中創建了此元素:

<a href="#"><h6>
    <strong>{{group.students.length}}
      {{group?.students?.length > 1 ? "Students attended" :
      "student attended" }}</strong></h6></a>

工作正常。 但是當我嘗試條件時n = 0像這樣:

<a href="#">
 <h6>
   <strong>{{group.students.length}}
  {{(group?.students?.length > 1 || group?.students?.length == 0 ) ? "Students attended" :
  "student attended" }}</strong>
 </h6>
</a>

這是行不通的。 如何在if條件中添加“或”?

也許這對於某些人來說似乎很明顯,但是我對ionic 3完全ionic 3所以如果這是一個愚蠢的問題,我感到抱歉。

謝謝 。

您僅需使用一個條件即可直接實現這一目標,即group?.students?.length == 1,因為在所有其他情況下,您都希望n個學生參加。

因此,您的更新代碼將是:

<a href="#">
 <h6>
   <strong>
     {{group.students.length}}
     {{group?.students?.length == 1  ? "student attended" : "Students attended" }}
</strong>
 </h6>
</a>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM