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