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