我的 ngModel 在选择时遇到问题,未显示为已选择。id 和 name 都匹配,但它不起作用,请参阅 selectedState。将模型指向选项数组中的实际对象有效,请参阅 selectedState2。不知道发生了什么...
小提琴:http: //jsfiddle.net/fedorsmirnoff/b49n4Ldp/2/
<select ng-model="selectedState" ng-options="state.name for state in stateOptions"></select>
<select ng-model="selectedState2" ng-options="state.name for state in stateOptions"></select>
function MainCtrl($scope) {
$scope.stateOptions = [
{id: 1, name: "Alaska"},
{id: 2, name: "Montana"},
{id: 3, name: "Nebraska"},
{id: 4, name: "Texas"}
]
$scope.selectedState = {id: 2, name: "Montana"};
$scope.selectedState2 = $scope.stateOptions[1];
}