Ng-Pluralize-1

 

In this example, we have an array named people with names. Ng pluralize directive is useful when we need to give description based on the count for example if one like on facebook then for count 1 we need to show that One person like this. In the same way in this example for the count 0 it will show that Nobody is viewing for count 1 it will show name of the first person ie Messi is viewing.

 
 
 
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Welcome to LearnKode - A code learning platform</title> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.2/angular.min.js"></script> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css"> </head> <body ng-app="pluralizeExample"> <div ng-controller="ExampleController"> <div class="container"> <div class="well"> <ng-pluralize count="people.length" when="{'0': 'Nobody is viewing.', '1': '{{people[0].name}} is viewing.', '2': '{{people[0].name}} and {{people[1].name}} are viewing.', 'one': '{{people[0].name}}, {{people[1].name}} and one other person are viewing.', 'other': '{{people[0].name}}, {{people[1].name}} and {{people.length-2}} other people are viewing.'}"> </ng-pluralize> </div> <pre>{{people}}</pre> </div> </div> <script> var app = angular.module("pluralizeExample", []); app.controller('ExampleController', ['$scope', function ($scope) { $scope.people = [{ name: "Messi" }, { name: "John" }, { name: "Emmi" }, { name: "Edvard" }, { name: "Kim" }, { name: "Kisdarm" }, { name: "wrwe" }]; }]); </script> </body> </html>
Output