Angular UI select2 - How to stop automatic sorting?

The following data is bound to select2 via the Angular User Interface : ( Live example here )

JS:

$scope.items = [
  {id: 1, text: 'elephant'}, 
  {id: 2, text: 'desk'}, 
  {id: 3, text: 'car'}, 
  {id: 4, text: 'boat'}, 
  {id: 5, text: 'apple'}
];
$scope.selected = [];

HTML:

<select ui-select2 
        multiple 
        ng-model="selected" 
        data-placeholder="Please select..." 
        style="width:200px">
  <option></option>
  <option ng-repeat="item in items" value="{{item.id}}">{{item.text}}</option>
</select>

However, each time item selected, it sorts the selected items into id. For example, if you select “apple” and then “boat”, the items selectedwill be “boat” and “apple” (in that order!).

How can I save an order and disable this automatic sorting?

+5
source share
1 answer

, , ng-options ng-repeat , ,

, , :

<option ng-repeat="item in items" value="{{item.id}}">{{item.text}}</option>

:

ng-options="item.text for item in items"

, , , .

-1

All Articles