Back to Tips

ngPlural

In order to make pluralization easier, Angular provides the ngPlural Directive which allows to display a particular template on a given value.

<p [ngPlural]="items.length">
  <ng-template ngPluralCase="=0">No items on the cart</ng-template>
  <ng-template ngPluralCase="=1">One item added to the cart</ng-template>
  <ng-template ngPluralCase="few">{{items.length}} items added to the cart</ng-template>
</p>

Support

If you enjoyed this tip and found it useful, consider buying me a coffee. Thanks in advance!

Buy Me a Coffee at ko-fi.com
Using Angular v.18.2.8 🚀