As long as you see this in the stream, the author answers the links in the link, I thought it would be nice to put one of the mentioned workarounds on SO:
It is true that this is not technically implemented, but there is some easy work if you want to slightly modify your data model: use a custom filter to create an array of object properties ( without ). If you add a key field to the objects ("id" in the above case), you can get the behavior you are looking for:
app.filter("toArray", function(){ return function(obj) { var result = []; angular.forEach(obj, function(val, key) { result.push(val); }); return result; }; }); ... $scope.users = { 1: {name: "John", email: "john@gmail.com", id: 1}, 2: {name: "Elisa", email: "elisa@gmail.com", id: 2} };
Here you can specify the ng-repeat directive:
<option value="{{user.id}}" ng-repeat="user in users | toArray | orderBy:'name'">{{user.name}}</option>
And here is plunkr .
Note that the orderBy filter takes name as its parameter, not user.name .
Unfortunately, adding the id property to your objects creates the potential for inconsistency with it in the containing object.
The link mentioned in your answer also suggests suggested solutions that create the id property on user objects on the fly, but I feel that this approach is a little less messy (by introducing replication data).
mhess Sep 22 '13 at 12:17 2013-09-22 00:17
source share