The last thing I checked, Angular does not support the ability to bind array keys to the ng model via ng-options. You can, however, simulate this behavior using an object hash:
menu.html:
<div ng-controller="menuCtrl"> <select ng-model="model.selectedLocation" ng-options="x.value as x.label for x in model.locations()"> </select> </div>
script.js
$scope.model.locations = function(){ var loc = [{ value: 0, label: 'Dublin' }, { value: 1, label: 'Stockholm' }, { value: 2, label: 'New Jersey' }]; $scope.model.selectedLocation = 1;
Keep in mind that this will associate integers with your model, and not with the cities themselves. If you want your model value to be Dublin , Stockholm or New Jersey , simply do:
menu.html:
<div ng-controller="menuCtrl"> <select ng-model="model.selectedLocation" ng-options="name for name in model.locations()"> </select> </div>
script.js
$scope.model.locations = function(){ var loc = ['Dublin', 'Stockholm', 'New Jersey']; $scope.model.selectedLocation = 'Dublin';
source share