angularjsangularjs-directiveangularjs-select2

AngularJS Select other option and get value from textbox


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>

Solution

  • 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>