简体   繁体   中英

how to select default value of ui select?

could you please tell me how to set default value in UI -select . here is my code http://plnkr.co/edit/tCrEM4oC9iMSYZffbEAX?p=preview I want "Adrian" should select as by default .could you please tell me how to set default value of Adrian age in model example (21) ?

<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>

Here you go: http://plnkr.co/edit/0AAniDzf7fdKywh4Rfk5?p=preview

You can't use age in this case, otherwise it would find all persons that have the same age, and end up using the last one. You need either an unique id, or use the name, as I did on my plunker

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

And on the select I've changed the repeat to repeat="color.name as color in people | filter:$select.search" .

Here's what would happen if you use the age instead: http://plnkr.co/edit/i6usxawmcnxYuqmH58kw?p=preview

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM