Reputation: 5083
I have a select element with ng-options
to populate options and <option value="">Select</option>
as a static default option. I want to show another item in options list - Other
, if selected, renders a textbox
for user to enter other value. I tried adding another static option with value="-1"
but it didn't work.
Upvotes: 0
Views: 3576
Reputation: 36030
I would try following:
<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>
or,
<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>
Upvotes: 2