2016-06-28 107 views
0

我遵循angularjs ui-select引導程序網站中的示例。angularjs ui-select設置默認值,並且不能選擇默認值

下面是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: '[email protected]',  age: 12, country: 'United States' }, 
{ name: 'Amalie', email: '[email protected]', age: 12, country: 'Argentina' }, 
{ name: 'Estefanía', email: '[email protected]', age: 21, country: 'Argentina' }, 
{ name: 'Adrian', email: '[email protected]', age: 21, country: 'Ecuador' }, 
{ name: 'Wladimir', email: '[email protected]', age: 30, country: 'Ecuador' }, 
{ name: 'Samantha', email: '[email protected]', age: 30, country: 'United States' }, 
{ name: 'Nicole', email: '[email protected]', age: 43, country: 'Colombia' }, 
{ name: 'Natasha', email: '[email protected]', age: 54, country: 'Ecuador' }, 
{ name: 'Michael', email: '[email protected]', age: 15, country: 'Colombia' }, 
{ name: 'Nicolás', email: '[email protected]', age: 43, country: 'Colombia' }]; 

    addoptions(); 
    function addoptions(){ 

    var tmp = { name: 'Nis', email: '[email protected]', age: 43, country: 'China' }; 
    $scope.people.push(tmp); 
    var tmp2 = {name: 'Emma', email: '[email protected]', 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。

回答

0

我看了一下你的問題,並舉了一個例子,我不能重現這個問題。你可以檢查你是否有0.17.1或0.17.2。在0.17.2中,他們在所選值默認值已經消失的情況下進行了一些更改。 這裏是the example link

- 
+0

謝謝你,我注意到,這是版本的問題,並使用0.16.0代替 – LizzyMiao

+0

大好運 – Jefiozie