Angularjs选择具有多个静态选项的选项

时间:2013-06-20 04:00:41

标签: angularjs

我有一个带ng-options的select元素来填充选项,<option value="">Select</option>作为静态默认选项。我想在选项列表中显示另一个项目 - Other,如果选中,则会为用户呈现textbox以输入其他值。我尝试使用value="-1"添加另一个静态选项,但它不起作用。

1 个答案:

答案 0 :(得分:2)

我会尝试以下:

<div ng-init="arr = [{name:'A', val:1},{name:'B', val:2},{name:'C', val:2}]">
  <select ng-model="v">
    <option ng-repeat="o in arr" value="o.val">{{ o.name }}</option>
    <option>Other</option>
  </select>
  <input type="number" ng-model="otherval" ng-show="v == 'other'"/>
</div>

,或者

<div ng-init="arr = [{name:'A', val:1},{name:'B', val:2},{name:'C', val:2}]">
  <select ng-model="v" ng-options="o.val as o.name for o in arr.concat([{name:'Other',val:'other'}])">
  </select>
  <input type="number" ng-model="otherval" ng-show="v == 'other'"/>
</div>