0

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 .

4
  • what do you mean by not working? what are you getting? Commented Jun 21, 2018 at 10:33
  • 1
    You can achieve it by using one condition only ,i.e., group?.students?.length == 1 because for all other cases you want n students attended. Commented Jun 21, 2018 at 10:45
  • I just tested your code. It totally works. Commented Jun 21, 2018 at 11:45
  • Thanks a lot @RachitShroff !! maybe you can post it as an answer so that I can vote it :D Many Thanks :))) Commented Jun 21, 2018 at 14:38

1 Answer 1

1

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>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.