我有以下plunker 我将ui-select绑定到控制器中定义的项目列表,如下所示:
app.controller('DemoCtrl', function ($scope, $http, $timeout, $interval) {
var vm = this;
vm.tester = 1;
vm.listItems = [
{ label: "aaa", value: 0, },
{ label: "bbb", value: 1, },
];
});
这是ui-select:
<ui-select reset-search-input="true"
ng-model="ctrl.tester">
<ui-select-match placeholder="">
{{$select.selected.text}}
</ui-select-match>
<ui-select-choices repeat="item.value as item in ctrl.listItems | filter: { label: $select.search }">
<span ng-bind-html="item.label" title="{{item.label}}"></span>
</ui-select-choices>
</ui-select>
问题是虽然ctrl.tester包含选定的值,但选择的值不会显示在ui-select中。
我必须遗漏一些非常明显但却找不到的东西。
答案 0 :(得分:1)
您需要更新html才能使用{{$select.selected.label}}
而不是{{$select.selected.text}}
<ui-select reset-search-input="true"
ng-model="ctrl.listItems.selected">
<ui-select-match placeholder="">
{{$select.selected.label}}
</ui-select-match>
<ui-select-choices repeat="item.value as item in ctrl.listItems | filter: { label: $select.search }">
<span ng-bind-html="item.label" title="{{item.label}}"></span>
</ui-select-choices>
</ui-select>