【问题标题】:ui-select does not display selected itemui-select 不显示选中项
【发布时间】:2017-12-20 17:23:42
【问题描述】:

我有一个关注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 中。

我一定遗漏了一些非常明显的东西,但找不到什么。

【问题讨论】:

  • 无法在任何地方看到控制器中定义的测试器范围变量。请添加完整代码
  • @RahulB:无论是否定义。但无论如何我将它添加到代码中,问题仍然存在。

标签: angularjs ui-select


【解决方案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>

【讨论】:

  • 感谢百万人 :) 我知道这是一些拼写错误,但找不到。有时它太大了,看不到:)
  • @jabko87 :没问题。您可以完全删除 tester 变量并仅将 listitems 用于选定对象。
猜你喜欢
  • 1970-01-01
  • 2019-07-03
  • 1970-01-01
  • 1970-01-01
  • 2015-10-03
  • 2021-03-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多