AngularJS – Select value property in ng-options

The angular select ng-options attribute is really useful to dynamically generate the options of a select. Additionally​, it brings another great benefit, the possibility​ of selecting as value other javascript data types and not only strings.

Example of use:

<script>
angular.module('demoApp', []).controller('DemoController', function($scope) {

 $scope.options = [
 { label: 'one', value: 1 },
 { label: 'two', value: 2 }
 ];
 
 $scope.numberSelected= $scope.options[1].value;
});
</script>

<body ng-app="demoApp">
  <div ng-controller="DemoController">
    <select ng-model="numberSelected" ng-options="opt.value as opt.label for opt in options">
    </select>

     The value selected is {{ numberSelected }}.
  </div>
</body>

Fiddler