-1

Given an ng-model as $scope.value = "b", how would I declare the syntax for ng-options to be able to select and save the value property of the following alternatives?

$scope.value = "b"
$scope.alternatives = [{
  text: "A",
  value: "a"
}, {
  text: "B",
  value: "b"
}, {
  text: "C",
  value: "c"
}];

What I want is that, when an option is selected, the model changes to lowercase "b". Currently it saves to the whole Object {"text":"B","value":"b"}

Plunkr: http://plnkr.co/edit/oupwDU8BZQ2WsJDeYbTv?p=preview

Fagner Brack
  • 2,365
  • 4
  • 33
  • 69
  • It would be very useful a justification for the "-1" on this question. Just because there is a duplicate answer, it doesn't mean this is a bad question, it just means I failed to find the duplicate due to the fact the duplicate doesn't express this specific context in the title, but rather a generic approach on how to handle `ng-options`. – Fagner Brack Jul 27 '15 at 13:27

1 Answers1

2

You would do:

<select ng-model="value" ng-options="obj.value as obj.text for obj in alternatives"></select>
tymeJV
  • 103,943
  • 14
  • 161
  • 157