This blog will help you understand the use of ng-Pluralize directive of AngularJS.

I have demonstrated the functionality of ng-Pluralize with an example. So, let's start with an array named as people.

As we see on Facebook, we have numbered likes on a post but it is in some formatted way, like Abc, Xyz + 20 others liked your post.

So, let's start creating the same thing with the help of ng-Pluralize directive of AngularJS.
Click to see the output
  1. <!DOCTYPE html>
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <title>Devmeal.com</title>
  5. <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.2/angular.min.js"></script>
  6. <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css"> </head>
  7. <body ng-app="pluralizeSampleApp">
  8. <div ng-controller="PluralController">
  9. <div class="container">
  10. <div class="well">
  11. <ng-pluralize count="people.length" when="{'0': 'Nobody is seeing.',
  12. '1': '{{people[0].name}} is viewing.',
  13. '2': '{{people[0].name}} and {{people[1].name}} are seeing.',
  14. 'one': '{{people[0].name}}, {{people[1].name}} and one other person are seeing.',
  15. 'other': '{{people[0].name}}, {{people[1].name}} and {{people.length-2}} other people are seeing.'}"> </ng-pluralize>
  16. </div>
  17. <pre>{{people}}</pre> </div>
  18. </div>
  19. <script>
  20. var app = angular.module("pluralizeSampleApp", []);
  21. app.controller('PluralController', ['$scope', function($scope) {
  22. $scope.people = [{
  23. name: "Jack"
  24. }, {
  25. name: "Denial"
  26. }, {
  27. name: "Liza"
  28. }, {
  29. name: "Dimko"
  30. }, {
  31. name: "Rossy"
  32. }, {
  33. name: "Luzy"
  34. }, {
  35. name: "Amik"
  36. }];
  37. }]);
  38. </script>
  39. </body>
  40. </html>