angularjs ui-select设置默认值,不能选择默认值

时间:2016-06-28 10:24:01

标签: angularjs ui-select

我按照angularjs ui-select bootstrap网站中的示例进行操作。

这是html部分代码:

  <div class="form-group">
    <div class="col-sm-6">
      <ui-select ng-model="ctrl.person.selected" theme="bootstrap">
        <ui-select-match placeholder="Select or search a person in the list...">{{$select.selected.name}}</ui-select-match>
        <ui-select-choices group-by="'country'" repeat="item in ctrl.people | filter: $select.search">
          <span ng-bind-html="item.name | highlight: $select.search"></span>
          <small ng-bind-html="item.email | highlight: $select.search"></small>
        </ui-select-choices>
      </ui-select>

以下是js部分代码:

  $scope.person = {};

$scope.people = [
{ name: 'Adam',      email: 'adam@email.com',      age: 12, country: 'United States' },
{ name: 'Amalie',    email: 'amalie@email.com',    age: 12, country: 'Argentina' },
{ name: 'Estefanía', email: 'estefania@email.com', age: 21, country: 'Argentina' },
{ name: 'Adrian',    email: 'adrian@email.com',    age: 21, country: 'Ecuador' },
{ name: 'Wladimir',  email: 'wladimir@email.com',  age: 30, country: 'Ecuador' },
{ name: 'Samantha',  email: 'samantha@email.com',  age: 30, country: 'United States' },
{ name: 'Nicole',    email: 'nicole@email.com',    age: 43, country: 'Colombia' },
{ name: 'Natasha',   email: 'natasha@email.com',   age: 54, country: 'Ecuador' },
{ name: 'Michael',   email: 'michael@email.com',   age: 15, country: 'Colombia' },
{ name: 'Nicolás',   email: 'nicolas@email.com',    age: 43, country: 'Colombia' }];

  addoptions();
  function addoptions(){

     var tmp = { name: 'Nis',   email: 'nis@email.com',    age: 43, country: 'China' };
     $scope.people.push(tmp);
     var tmp2 = {name: 'Emma',   email: 'Emma@email.com',    age: 43, country: 'China'};
     $scope.people.push(tmp2);
     $scope.person.selected = $scope.people[0]; 
  }

下拉列表应该看起来像右侧,但我看起来就像左边的sie:

enter image description here

另外,我注意到一件事,一旦我设置了默认的person.select,那就是$$ haskkey $scope.people[0],不再存在。 我的ui select版本是0.17.1。

1 个答案:

答案 0 :(得分:0)

我看了一下你的问题并做了一个例子,我无法重现这个问题。你能检查一下你是否有0.17.1或0.17.2。在0.17.2中,他们在所选值默认值消失的情况下进行了一些更改。 这是the example link

 -