In previous examples, we used an array as the data source, but we can also work with an object that contains key-value pairs.
$scope.cars = { car01 : “Ford”, car02 : “Fiat”, car03 : “Volvo” }; |
When using an object as the data source, x represents the key, while y represents the value.
<select ng-model=”selectedCar” ng-options=”x for (x, y) in cars“> </select> <h1>You selected: {{selectedCar}}</h1> |
The selected value will always match the value in a key-value pair, which can also be an object.