Suppose I have the following users:
$scope.users = {
"2": {
email: '[email protected]',
name: 'John'
},
"3": {
email: '[email protected]',
name: 'Elisa'
}
}
I would like to create a <select> with the following options:
<option value="3">Elisa</option>
<option value="2">John</option>
In other words, users should be sorted by name.
I tried the following using the (key, value) in expression syntax, but it doesn't work:
<option ng-repeat="(user_id, user) in users | orderBy:'user.name'"
value="{{ user.id }}">
{{ user.name }}
</option>
What am I missing?
Please do not suggest solutions with ng-options as I use ui-select2 which is incompatible with ng-options.
ng-repeatandorderByare very common things in AngularJS. I believe there will be much more questions regarding these two. But ,anyway, I added these tags to some other questions.ngRepeatwould becomeng-repeat, whileorderBybecomesorderby.