Search code examples
angularconditional-operatorstring-interpolation

Display "99+" if a number is greater than some value I assign


I have a dynamic numbers count that comes to my notification variable.

I'm using the ternary operator to display that number if it is less than 99, otherwise, I want to display "99+".

I have tried this:

<div class="notification-badge" *ngIf="unreadNotificationsCount > 0">
  {{(unreadNotificationsCount < 99) ? {{unreadNotificationsCount}} : '99+'}}

..but it doesn't allow string interpolation inside the ternary


Solution

  • Too many {s.

    {{ (unreadNotificationsCount < 99) ? unreadNotificationsCount : '99+' }}
    

    should work.