How to format a number in ng:pluralize


How to format a number passed into ng:pluralize directive via attribtute ‘count’?

Consider following code:

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

the output is:

5000000 things

How can I modify this for output to be:

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

I tried using filter ‘number’, but I think I don’t know where to put it. It doesn’t work in the object passed to attribute ‘when’. I tried these:

... when="{'many': '{{{}|number}} things'}"
... when="{'many': '{}|number things'}"
... when="{'many': '{|number} things'}"

Problem courtesy of: redhead


You need to assign the value to a variable

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

This will format the value to the current locale rules


Solution courtesy of: Liviu T.

View additional discussion.

Like what you read? Give Angular.js Recipes a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.