pietà
pietà

Reputation: 770

if else condition in angular html tag with "or"

I have to show number of elements in html I want it to show "n students attended" when n>1 or n = 0 and 1 student attended" when it's an only one : n=1 student. So I created this in html :

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

it's working fine. but when I tried the condition when n=0 like this :

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

This is not working. How can I add "or" in the if condition ?

Maybe it seems to be obvious to some people but I'm totally new with ionic 3 so I'm sorry if it's a stupid question.

Thanks .

Upvotes: 0

Views: 3031

Answers (1)

Rachit Shroff
Rachit Shroff

Reputation: 135

You can achieve it directly by using only one condition only ,i.e., group?.students?.length == 1 because for all other cases you want n students attended.

So your update code will be:

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

Upvotes: 1

Related Questions