angularjsangularjs-directiveangular-chosen

ngOptions syntax for displaying key and value in option tag


I have an array of country objects and trying to display a dropdown using Angular chosen

Angular chosen does not support ng-repeat for the options tag, instead it only supports ngOptions.

My ngOptions syntax is as follows

<select chosen class="form-control input-lg" name="countryDropdown" id="countryDropdown"
ng-options="option.name+option.d_code for option in loginCtrl.countryData track by option.code"
ng-model="loginCtrl.selectedOption">

 </select>

I want to display both the country name and code i.e India IN but it displays without a space between them i.e. INDIA+91,

How do I add a space between the name and the code?

Sample country object:

{
   name: India,
   d_code: +91,
   code: IN

}

Solution

  • just add the space in the string

    ng-options="option.name+' '+option.d_code for option in loginCtrl.countryData track by option.code"