当NG-模型initalized角UI选占位符不工作 [英] Angular ui-select placeholder not working when ng-model is initalized

查看:320
本文介绍了当NG-模型initalized角UI选占位符不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想添加一个新的选择每次按钮被点击时,

I am trying to add a new select every time a button is clicked,

该HTML:

 <div ng-repeat = "select in selects track by $index">
  <ui-select ng-model="selects[$index]" theme="select2" ng-disabled="disabled" style="min-width: 300px;">
    <ui-select-match placeholder="Select a person in the list or search his name/age...">{{$select.selected.name}}</ui-select-match>
    <ui-select-choices repeat="person in people">
      <div ng-bind-html="person.name | highlight: $select.search"></div>
    </ui-select-choices>
  </ui-select>
 </div>
 <button ng-click="addNewSelect()"> Add new select</button>

控制器:

  $scope.selects = [{}];
  $scope.addNewSelect = function() {
    $scope.selects.push({});
  }

对象的数组被保存在数组'选择',但是因为我有一个空的对象最初初始化NG-模型中的占位符不是在选择未来。如何得到他的占位符在这种情况下工作吗?

The array of objects gets saved in the array 'selects', but the placeholder is not coming in the selects as I am initializing the ng-model with an empty object initially. How to get he placeholder working in this case ?

下面是 Plunker 以相同的。

推荐答案

您缺少 .selected 后选择[$指数]

如果没有这个,用户界面​​选认为,你选择一个空的对象(选择[$指数] ),并不会显示占位符。

Without this, the ui-select believes that you have selected an empty object (the selects[$index]) and won't show the placeholder.

<ui-select ng-model="selects[$index].selected" theme="select2" ng-disabled="disabled" style="min-width: 300px;">

http://plnkr.co/edit/56SHyE01BJ4EXglLlIcb?p=$p$ PVIEW

还你不需要查找使用索引,你可以使用 select.selected

also you dont need to look up using the index, you can just use select.selected

<ui-select ng-model="select.selected" theme="select2" ng-disabled="disabled" style="min-width: 300px;">

http://plnkr.co/edit/3Uq8lDtDOaj5mIZVrCfv?p=$p$ PVIEW

这篇关于当NG-模型initalized角UI选占位符不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆