相关疑难解决方法(0)

初始化ng-model时,Angular ui-select占位符不起作用

我试图在每次点击按钮时添加一个新的选择,

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>
Run Code Online (Sandbox Code Playgroud)

控制器:

  $scope.selects = [{}];
  $scope.addNewSelect = function() {
    $scope.selects.push({});
  }
Run Code Online (Sandbox Code Playgroud)

对象数组保存在数组'choices'中,但占位符不在选择中,因为我最初使用空对象初始化ng-model.如何让占位符在这种情况下工作?

这是相同的Plunker.

javascript select angularjs angularjs-select2 ui-select

3
推荐指数
1
解决办法
7855
查看次数