Search code examples
angularjsangular-uiangular-ngmodelng-optionsangular-ui-select

How do I convert from ngOptions to angular-ui-select?


I'm trying to add searchability to my select with the angular-ui-select directive. When I use angular-ui-select, the model value turns into the entire timezone, not just the id.

Here's the code:

<!-- select with ngOptions doing what I want -->
<select data-ng-model="clock.time_zone_id" data-ng-options="timeZone.id as timeZone.name for timeZone in timeZones"></select>

<!-- my best try with angular-ui-select -->
<ui-select data-ng-model="clock.time_zone_id" theme="selectize">
  <ui-select-match>{{$select.selected.name}}</ui-select-match>
  <ui-select-choices repeat="timeZone in timeZones | filter: $select.search">
    <span ng-bind-html="timeZone.name | highlight: $select.search"></span>
  </ui-select-choices>
</ui-select>

What am I missing? I'd appreciate any help!


Solution

  • This should work:

    <ui-select data-ng-model="clock.time_zone_id" theme="selectize">
      <ui-select-match>{{$select.selected.name}}</ui-select-match>
      <ui-select-choices repeat="timeZone.id as timeZone in timeZones | filter: $select.search">
        <span ng-bind-html="timeZone.name | highlight: $select.search"></span>
      </ui-select-choices>
    </ui-select>