Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

4
  • With ngOptions you can't force angular to use your model-data as the actual option-value in the view. Angular handles this in it's own way. It only assures that your scope-model will be set to the correct value on change. If that's not what you want, than you'll have to write your own directive, probably using ngRepeat. Commented Aug 25, 2014 at 21:54
  • That's fine; I don't have to have "foo.bar_id" as the option value; I just have to have it available so when the user selects an option it is inserted into a corresponding url parameter to update the display. Commented Aug 25, 2014 at 22:04
  • My main concern is what goes in $scope.typeOptions (using the example from the other thread above) INSTEAD OF an array, to get foo.name and foo.bar_id key-value pairs from the data object foo. I have tried putting <select ng-model='fooOptions' ng-options='foo.name as foo.bar_id for foo in fooOptions'></select> but it does not work -- nothing shows up. When I use those as an ng-repeat in the option tag it works (foo.name and foo.bar_id) so the problem isn't with the object properties themselves. Commented Aug 25, 2014 at 22:08
  • I see, no you'll always need two seperate models. One which acts as the list of options (this should probably always be an array of objects) and one to store the selected value (this will then differ in regards to how you set up the ngOptions directive). Commented Aug 26, 2014 at 6:55