Search code examples
javascriptangularjsng-options

Add "%" suffix in ng-options with AngularJS


I want to include % symbol in the options of an array using ng-options.

Here is the code:

$scope.load_percentages = [0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50];

<select ng-model="loaddata.loadPercent" ng-options="loadpercentnumber as {loadpercentnumber + '%' +} for loadpercentnumber in load_percentages track by loadpercentnumber"> 
</select>

But getting error like not correct way


Solution

  • Don't use bracets:

    ng-options="loadpercentnumber as loadpercentnumber + '%' for loadpercentnumber in load_percentages track by loadpercentnumber"
    

    JSFiddle demo