AngularJS Select other option and get value from textbox

Muffin picture Muffin · Jul 16, 2014 · Viewed 11.3k times · Source

Using AngularJS I have a list of selected option and one additional "New" option. What I am trying to do is, when "New" option is chosen it will show a text-box to add a new value.

<select ng-model="group.name" ng-options="bl.Name for bl in Groups" >
      <option value="VALUE FROM TEXT BOX">New</option>
</select> 

<div class="col-md-4" ng-show="WHEN NEW OPTION IS Chosen ">
<input class="text-box" type="text" name="NewValue" ng-model="group.name" />
</div>

Answer

Nidhish Krishnan picture Nidhish Krishnan · Jul 16, 2014

You can try like this

Working Demo

<div ng-app='myApp' ng-controller="ArrayController">
    <select ng-model="group.name" ng-options="Group.Name for Group in Groups"></select>
    <div class="col-md-4" ng-show="group.name.Value == 'new'">
        <input class="text-box" type="text" name="NewValue" ng-model="newValue" />
        <button ng-click="add(newValue)">Add</button>
    </div>
</div>