Skip to content Skip to sidebar Skip to footer

Using NgPluralize Within Select

Is it possible to use ngPluralize inside of a select tag configured with ngOoptions to pluralize the options of the dropdown list? I currently have the following controller functio

Solution 1:

As Dmitry explained, ngPluralize cannot be used with ngOptions, but nothing stops you from using it with ngRepeat:

HTML:

<body ng-controller="AppController">

  <select ng-model="selectedRange">
    <option value="">Select number ...</option>
    <option 
      ng-repeat="range in ranges"
      ng-pluralize
      count="range"
      when="{1: '{{range}} minute', other: '{{range}} minutes'}"
    >{{range}}</option>  
  </select>

</body>

JS:

app.controller('AppController',
    [
      '$scope',
      function($scope) {
        $scope.ranges = [1, 2, 3, 4, 5];
        $scope.selectedRange = $scope.ranges[4];
      }
    ]
  );

Plunker

By the way, about your "pre-select" troubles, be aware that JavaScript arrays are zero-indexed.


Post a Comment for "Using NgPluralize Within Select"