How to format a number in ng: pluralize

How to format the number passed to ng: the pluralize directive via the 'count' attribute?

Consider the following code:

<ng:pluralize count="5000000" when="{'other': '{} things'}"></pluralize> 

output:

 5000000 things 

How can I change this to output:

 5,000,000 things // in US locale 5 000 000 things // in Czech locale 

I tried using the filter number, but I think I don’t know where to put it. It does not work on the object passed to the when attribute. I tried:

 ... when="{'many': '{{{}|number}} things'}" ... when="{'many': '{}|number things'}" ... when="{'many': '{|number} things'}" 
+8
angularjs
source share
2 answers

You need to assign a value to a variable

  <ng:pluralize ng-init="myCount=5000000" count="myCount" when="{'other': '{{myCount|number}} things'}"></ng:pluralize> 

This will format the value for the current locale rules.

Demo

+13
source share

Turning to @Liviu T., there is no real need to use ng-init to assign a variable. You can do it right on the bill.

 <ng:pluralize count="myCount=5000000" when="{'other': '{{myCount|number}} things'}"></ng:pluralize> 
+1
source share

All Articles