Is there a easy way to have options as objects in array? Like following:

$scope.search.categories = [{id: '1',name: 'first'},{id: '2',name: 'last'}];

<select ui-select2 ng-model="search.categories" multiple style="width:300px" data-placeholder="select category">
  <option ng-repeat="category in search.categories" value="{{category}}">{{category.name}}</option>

</select>

Or am I totally wrong?

share|improve this question

feedback

2 Answers

up vote 1 down vote accepted

Checkout this demo I've put together: http://plnkr.co/edit/gist:4279651?p=preview

If you want the selected item to be an object use <input>

The demo shows you 4 different ways to do uiSelect2

share|improve this answer
feedback

Yes, use the ng-options and the ng-model like this:

<select ui-select2 ng-model="selectedCategory" ng-options="c.name for c in search.categories">
  <option value="">Pick a category</option>
</select>

Note: $scope.selectedCategory will hold the reference to the selected category object.

share|improve this answer
thank you! will try it out, but how about info at angular-ui.github.com saying: ui-select2 is incompatible with <select ng-options>. For the best results use <option ng-repeat> instead What is your experience? Is it safe? – Jakub Kuchar Jan 15 at 12:07
feedback

Your Answer

 
or
required, but never shown
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.