Select a value with custom empty option
Description
The following code shows how to select a value with custom 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', []);
<!--from w w w .j a v a 2 s . c o 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">
<option value="">--</option>
</select>
Selected Letter: {{ letter }} ({{ getType(letter) }})
</body>
</html>