Search code examples
angularjsdropdownbox

Angularjs dropdown text need to be showing as a title of the dropdown


I have a requirement where I need to show the text of angularjs dropdown (Not value) in the title tag of the dropdown box. My angular code is like this :

  <select id="inputID" name="inputName" 
  ng-options="item.value as item.display for item in genders" 
  ng-model="model.Base.currentRecord.value.Code.value" class="form-control input-sm">
   <option value="">Select...</option> </select>

As the dropdown is being generated dynamical, the value of the options and the text in the options are different. in the title tag I am able to get the value with title={{model.Base.currentRecord.value.Code.value}} but I need text not the value.

anyone has any idea ?


Solution

  • Would this work? demo

    <select id="inputID" title={{model.Base.currentRecord.value.Code.display}} name="inputName" ng-options=" item.display for item in genders" 
    ng-model="model.Base.currentRecord.value.Code" class="form-control input-sm">
      <option value="">Select...</option>
    </select>
    <strong>Selected value:</strong> {{model.Base.currentRecord.value.Code.value}}