Mathematics Mathematics - 1 month ago 10
AngularJS Question

How to add suffix to only 1 option in angularjs select based on data variable

I have a select like this in angularjs,

<select id="contact">
<option value="HOME">Home - {{data.Home}}</option>
<option value="WORK">Work - {{data.Work}}</option>
<option value="GYM">Gym - {{data.Gym}}</option>
</select>


How can I add text "Preferred" to end of option based on variable
data.Preferred


data.Preferred
value is same as option's values.

Answer

I think it would make more sense, if possible to decorate it in the controller, but something like this should work:

<select id="contact">
  <option value="HOME">Home - {{data.Preferred === 'HOME' ? 'Preferred' : ''}}</option>
  <option value="WORK">Work - {{data.Preferred === 'WORK' ? 'Preferred' : ''}}</option>
  <option value="GYM">Gym - {{data.Preferred === 'GYM' ? 'Preferred' : ''}}</option>
</select>