0

I would like to order the <option>s of a <select> by the values of an object, using ng-options.

function Ctrl($scope) {
  $scope.people = {'A1': 'Adam Smith', 'A2': 'Adam Adams'};
}


<select ng-model="selected"
  ng-options="name for (userid, name) in people | orderBy:'name'"
></select>

http://jsfiddle.net/9k1686jt/

However, the orderBy filter doesn't seem to have any effect.

Expected output:

...
<option ...>Adam Adams</option>
<option ...>Adam Smith</option>
...

Actual output:

...
<option ...>Adam Smith</option>
<option ...>Adam Adams</option>
...

How can I use ng-options to produce the Expected output?

I'm using Angular 1.3

mark
  • 4,678
  • 7
  • 36
  • 46
  • Your example doesn't have a `name` property to use the orderBy filter, so it just defaults to the original list (which has Adam Smith first). This fiddle works: http://jsfiddle.net/naetrz0g/ – Jon La Marr Jul 11 '17 at 21:27
  • You could consider reform your JSON and then use `orderBy` filter like [this answer](https://stackoverflow.com/a/30621111/2435473) – Pankaj Parkar Jul 11 '17 at 21:28

0 Answers0