I'm encountering an issue while attempting to populate a select drop-down with data using AngularJS ng-repeat directive. Upon page load, the drop-down displays an empty option. How can I eliminate this empty item from showing up? Here is the snippet of code:
<html>
<head>
</head>
<body ng-app="app">
<div ng-controller="homeCtrl">
<select ng-model="selected">
<option ng-repeat="item in items" value="{{item.id}}">
{{item.name}}
</option>
</select>
<span>
{{selected}}
</span>
</div>
</body>
</html>
Below is the corresponding JS code:
var app = angular.module('app',[]);
app.controller('homeCtrl',['$scope',function($scope){
$scope.selected = 1;
$scope.items=[
{name: 'harry111',id:1},
{name: 'rimmi',id:2}
];
}]);
Feel free to check out the live DEMO