我正在尝试创建一个下拉列表,并希望用对象预填充它。
<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>
但是国家的下降并没有预先填充国家对象。我不确定是什么问题。
JSFIDDLE链接:http://jsfiddle.net/6qo3vs6c/