使用AngularJS在ng-options中添加“%”后缀

时间:2017-03-07 13:20:28

标签: javascript angularjs ng-options

我希望使用ng-options在数组的选项中包含符号。

以下是代码:

$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>

但是错误就像错误一样

3 个答案:

答案 0 :(得分:0)

不要使用支架:

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

JSFiddle demo

答案 1 :(得分:0)

你几乎做对了。 使用:

<select ng-model="loaddata.loadPercent" name="loadPercent" ng-options="o as o+'%' for o in load_percentages"> 
</select>

请参阅this JSFiddle example

答案 2 :(得分:-1)

尝试使用此代替实际的%符号:&#37;