0

我有一个选择元素,ng-options用于填充选项并<option value="">Select</option>作为静态默认选项。我想在选项列表中显示另一个项目 -Other如果选中,则呈现一个textbox供用户输入其他值。我尝试添加另一个静态选项,value="-1"但没有奏效。

4

1 回答 1

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>
于 2013-06-20T09:16:08.737 回答