ng-options为每个选项添加后缀

时间:2014-08-07 08:24:26

标签: javascript angularjs

假设我有以下带字符串的数组:

$scope.open_slots = ["00","10","50"],我希望得到以下结果:

enter image description here

不执行此操作:$scope.open_slots = ["00 minutes","10 minutes","50 minutes"]

如何为选项选项列表中的每个项目添加后缀?

这是我的代码:

 <select data-ng-model="minutes_per_slot" data-ng-options="item for item in open_slots"></select>

2 个答案:

答案 0 :(得分:11)

您可以使用as

ngOptions部分来完成此操作
ng-options="slot as slot+' minutes' for slot in open_slots">

另请参阅此 short demo

答案 1 :(得分:2)

尝试:

<select data-ng-model="minutes_per_slot" 
        data-ng-options="item as item + ' minutes' for item in open_slots">