AngularJS empty value in select
Why AngularJS adds a question mark inside select element?
Answer on my blog http://vincentaudebert.github.io/
HTML
<div ng-controller="selectController">
<div>
Select not initialized:
<select class="form-control" ng-model="selectedBook_noinit" ng-options="book.id as book.title for book in books"></select>
</div>
<div>
Select initialized to a specific value:
<select class="form-control" ng-model="selectedBook" ng-options="book.id as book.title for book in books" ng-init="selectedBook=init($index)"></select>
</div>
</div>
JavaScript
angular.module("SelectModule", [])
.controller("selectController", function selectController($scope) {
$scope.books = [
{
"id": 0,
"title": "Title Book #1"
},
{
"id": 1,
"title": "Title Book #2"
},
{
"id": 2,
"title": "Title Book #3"
},
];
$scope.init = function (index){
return 0;
}
});