I am trying to create a dropdown and want to prepopulate it with object.
<script>
angular.module("myapp", [])
.controller("MyController", function($scope) {
$scope.country = {
id: "2",
name: "USA"
};
$scope.countries = [{
id: "1",
name: "India"
}, {
id: "2",
name: "USA"
}, {
id: "3",
name: "UK"
}, {
id: "4",
name: "Nepal"
}];
});
</script>
<div>
Country Name :
<select ng-model="country" ng-options="country as country.name for country in countries"></select>
</div>
But the countries dropdown is not being prepopulated with country object.I am not sure what is the problem.
JSFIDDLE link :http://jsfiddle.net/6qo3vs6c/