【发布时间】:2023-04-07 20:15:02
【问题描述】:
请查看以下内容: http://plnkr.co/edit/fc9XcyyYGtAk0aGVV35t?p=preview
<ui-select ng-model="fm.countryCode" id="countryCode">
<ui-select-match placeholder="Select a country...">{{$select.selected.label}}</ui-select-match>
<ui-select-choices repeat="item in countries | filter: $select.search" value="{{$select.selected.value}}">
<div ng-bind-html="item.label | highlight: $select.search"></div>
<small ng-bind-html="item.value | highlight: $select.search"></small>
</ui-select-choices>
</ui-select>
我正在尝试让 ui-select 将 fm.countryCode 设置为所选项目的值。目前它只是将 fm.countryCode 设置为整个国家项目。例如,如果我选择阿富汗,fm.countryCode 将设置为 {"value":"AF","label":"Afghanistan"}。我想要的是“AF”。
我必须设置一个 $watch 来实现这一点还是有更优雅的解决方案?
【问题讨论】:
标签: angularjs