0

可否請你告訴我如何在UI選擇中設置默認值。 這裏是我的代碼 http://plnkr.co/edit/tCrEM4oC9iMSYZffbEAX?p=preview 我想「阿德里安」應該選擇作爲默認.could請你告訴我如何設置阿德里安年齡典範(21)的默認值?如何選擇ui select的默認值?

<ui-select tagging tagging-label="new tag" multiple ng-model="model.multipleDemo" theme="select2" ng-disabled="disabled" style="width: 300px;"> 
    <ui-select-match placeholder="Select colors...">{{$item.name}}</ui-select-match> 
    <ui-select-choices repeat="color.age as color in people | filter:$select.search"> 
     {{color.name}} 
    </ui-select-choices> 
</ui-select> 
<p>Selected: {{model.multipleDemo}}</p> 

回答

2

在這裏你去:http://plnkr.co/edit/0AAniDzf7fdKywh4Rfk5?p=preview

不能使用年齡在這種情況下,否則會發現,有同年齡的所有人,並最終使用最後一個。您需要用一個唯一的ID,或使用的名稱,因爲我做了我的plunker

$scope.model.multipleDemo.push('Adrian');

而且在選擇我已經改變了重複到repeat="color.name as color in people | filter:$select.search"

下面是如果使用年齡替代會發生什麼情況:http://plnkr.co/edit/i6usxawmcnxYuqmH58kw?p=preview