texas697
texas697

Reputation: 6417

How to bind the Id of a select box selection

I have a select box that displays GeoAreaName, I need the GeoAreaId of that selection to populate a input field. I have done something similar with a typeahead input but I am unable to apply it here. plunkr

<label>Geo&nbsp;Area:</label>
  <select ng-controller="JobMiscCtrl"  ng-model="currentItem.GeoAreaName" ng-options="job.GeoAreaName for job in geoAreaArray">
   <option value=""></option>
  </select>

  <input type="number" ng-model="currentItem.GeoAreaId" />

Upvotes: 0

Views: 40

Answers (1)

Angad
Angad

Reputation: 3429

I have edited your plunker. http://plnkr.co/edit/Ms3qPcwj6dxVF3y75ljZ?p=preview

You had 2 problems.

  • Your input field was out of the scope of your ng-controller declaration
  • Your ng-options expression needed to be slightly different.

    <select 
       ng-model="currentItem" 
       ng-options="job.GeoAreaId as job.GeoAreaName for job in geoAreaArray">
        <option value=""></option>
    </select>
    

Upvotes: 2

Related Questions