如何从ngOptions转换为angular-ui-select?

时间:2015-03-30 16:50:39

标签: angularjs angular-ui angular-ngmodel ng-options angular-ui-select

我正在尝试使用angular-ui-select指令为我的select添加可搜索性。当我使用angular-ui-select时,模型值将变为整个时区,而不仅仅是id。

以下是代码:

<!-- 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>

我错过了什么?我很感激任何帮助!

1 个答案:

答案 0 :(得分:1)

这应该有效:

<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>