【发布时间】:2018-06-21 22:41:53
【问题描述】:
我必须在 html 中显示元素的数量 我希望它在 n>1 或 n = 0 时显示“n 个学生参加” 和 1 名学生参加”当它是唯一的一个时: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 完全陌生,所以如果这是一个愚蠢的问题,我很抱歉。
谢谢。
【问题讨论】:
-
你说的不工作是什么意思?你得到了什么?
-
您可以通过仅使用一个条件来实现它,即 group?.students?.length == 1 因为对于所有其他情况,您希望 n 个学生参加。
-
我刚刚测试了你的代码。它完全有效。
-
非常感谢@RachitShroff!也许您可以将其发布为答案,以便我投票:D 非常感谢 :)))
标签: html angular if-statement ionic3