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:

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

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

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

     The value selected is {{ numberSelected }}.



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.