【问题标题】:ui-select error "Can't interpolate: {{$select.getPlaceholder()}}"ui-select 错误“无法插值:{{$select.getPlaceholder()}}”
【发布时间】:2015-03-30 23:02:54
【问题描述】:

这是我在 angular ui-select 中得到的完整错误

Error: [$interpolate:interr] Can't interpolate: {{$select.getPlaceholder()}} TypeError: Cannot read property 'length' of undefined

我的标记是:

  <ui-select multiple ng-model="case.keywords" theme="bootstrap">
    <ui-select-match placeholder="Select keywords...">{{$item.name}}</ui-select-match>
    <ui-select-choices repeat="keywords in keywords | filter: $select.search">
      <div ng-bind-html="keyword.name | highlight: $select.search"></div>
    </ui-select-choices>
  </ui-select>
<p>Selected: {{case.keywords}}</p>

除了getting 来自 db 的关键字数组之外,控制器中没有什么特别之处。显然ngSanitizeui.select都包含在模块依赖中。

我遇到的另一个问题是选择不可见。我可以显示选定的选项,但选项列表不可见。我正在使用引导主题,select.css 被引用。这是它的样子

感谢您的帮助。

【问题讨论】:

  • github.com/angular-ui/ui-select/wiki/ui-select 这是 ui-select 的 wiki。它显示了如何使用$select。我只是从那里拿走了它
  • 您使用的是哪个版本的 angular 和 ui-select?
  • 您能说出“关键字”的设置方式和时间吗?还有 case.keywords ? .我试图理解这个序列。另外,关键字列表是否大于 Case.Keywords?如果是,您应该在单击 UISelect 时看到选项(但这些选项不会显示所选项目)
  • 最有可能的问题是,uiselect 将列表设为未定义,并且它正在其上运行转发器,因此未定义长度。您可以尝试在加载时设置关键字 =[],我想这应该可以解决您看到的错误
  • @Sincere 还有角度版本?我问的原因是我推迟了从 ui-select2 迁移,即使它在 ui-select 中的某些错误已被弃用 b/c。我相信在 1.2.18 版本之前,一些带有引导主题的多项选择无法正常工作。

标签: angularjs ui-select


【解决方案1】:

来自@SunilVurity 和@Fiver 的问题给了我提示,引导我解决问题:

首先我将keywords改为keyword

<ui-select-choices repeat="keywords in keywords | filter: $select.search">

第二个在我的控制器中:

appFactory.getKeywords().then(function (keywords){
  $scope.keywords = keywords;
  $scope.case = {};
  $scope.case.selectedKeywords = [];
});

我改成了:

$scope.case = {};
$scope.keywords = [];
learningCasesFactory.getKeywords().then(function (keywords){
  $scope.keywords = keywords;
  $scope.case.selectedKeywords = [];
});

正如您在控制器中看到的,get 函数是异步的,它在加载时向视图返回一个未定义的列表,这导致了我在问题中提到的错误。更新控制器后,错误消失了。这个 SO 问题帮助了AngularJS Interpolation Error

第三uiselectangular 版本可能会导致问题。我的角度版本是 1.2.9。这个ui-select Github issue 说明升级angular版本解决了问题,我升级到1.3.11

感谢@SunilVurity 和@Fiver

【讨论】:

  • 太棒了!!很高兴知道我能以某种方式提供帮助
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多