Jakub Kuchar
Jakub Kuchar

Reputation: 1665

Angular UI / select2 multiple how to preselect values/options?

using angular-ui with select2 as follows:

<select ui-select2 ng-model="search.categories" multiple style="width:300px" data-placeholder="select category">
      <option value="open" >open</option>
      <option value="close" >close</option>
</select>

Where and how should I preselect options? By default selected option is only first.Somehow in controller?

Upvotes: 4

Views: 5433

Answers (1)

ProLoser
ProLoser

Reputation: 4616

For a simple <select> list it's easy:

MyController function($scope) {
    $scope.search = {
        categories: 'close'
    };
}

For <input> it gets trickier because you may need to add a initSelection option

Upvotes: 2

Related Questions