javascript, Uncategorized

AngularJS Pluralize – build a friendly message, good ui practice

Have you noticed that some web apps creators absolutely ignore common grammar in message or labels?

Well it is common.

You have 1 messages.

Or it might be cooler and human like but still:

You have one messages.

 

What you’d want to do in your AngularJS application is use a wonderful directive that is baked in and helps you avoid such mishaps.

 

<ng-pluralize count="report.CriteriaSelected.length"
                 when="{'0': 'No criterion is selected',
                     'one': '1 Criterion is selected',
                     'other': '{} Criteria selected’}"

What this will nicely take care for you are the conditions when Nothing is selected or you have 1 or many conditions where a different text is used.

Thereby avoiding using “message(s)”.

 

Going further, i would suggest using internationalization i18n for your labels in such cases so that it makes sense in other languages.

 

This feature exists for a while now.

 

Enjoy

Share This:

Leave a Reply