0
http://jsfiddle.net/aBccw/

<div ng-options="f.name for f in JSONArray | orderBy:'f.name'" ng-model="selected" ></div>

This is just dirty representation of actual code, it might contain syntactical errors, But what my question is that I don't want whole object in ng-model. I need a property of Object say age. But if I write

<div ng-options="f.age as f.name for f in JSONArray | orderBy:'f.age'"......

orderBy won't work correctly. How can I make orderBy work with the latter one.

Rishi
  • 1,646
  • 2
  • 15
  • 34

1 Answers1

0

To sort using a property, say age in your case, the correct syntax is this:

<select ng-model="selected" ng-options="f.name for f in friends | orderBy:'age'"></select>

Fiddle

Omri Aharon
  • 16,959
  • 5
  • 40
  • 58
  • Yes, It would work. But see I want f.age as ng-model value. Even in this case whole object would be stored in "selected". any thoughts? – Rishi Mar 03 '15 at 04:41
  • 1
    @RishiPrakash Oh I see what you mean, I'm afraid I don't think it's possible using `ng-options`. – Omri Aharon Mar 03 '15 at 06:42
  • Omri Aharon ,can this problem be tackled with using ng-repeat? – Rishi Mar 03 '15 at 11:18
  • @RishiPrakash I believe so, take a look here I think it will help you: http://stackoverflow.com/questions/18647098/initializing-select-with-angularjs-and-ng-repeat – Omri Aharon Mar 03 '15 at 12:29