Select value with auto generated empty option
Description
The following code shows how to select value with auto generated empty option.
Example
<!DOCTYPE html>
<html ng-app="myApp">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.js"></script>
<script>
var app = angular.module('myApp', []);
<!-- w w w.j a va 2s .co m-->
app.controller('MainCtrl', function($scope) {
$scope.letters = ['A', 'B', 'C', 'D'];
$scope.letter = 'E';
$scope.getType = function(item) {
if ( angular.isDefined(item) ) {
if ( item === null ) {
return 'null';
}
return typeof item;
}
return 'undefined';
};
});
</script>
</head>
<body ng-controller="MainCtrl">
<select ng-model="letter" ng-options="letter for letter in letters"></select>
Selected Letter: {{ letter }} ({{ getType(letter) }})
</body>
</html>