在我的控制器中:
$scope.usercountry[key]='101'; //this one is selected correctly
$scope.usercountry[key]=value.countryid; //this is not selected
在html视图中选择的是
HTML:
<select id ="red" style="width:90%;" class="form-control state state1" name="state_list" ng-change="getstate(0)" ng-model="usercountry[0]">
<option value="">--Country--</option>
<option ng-repeat="country in countryies" ng-selected="country.id==selectedCountryvalue[0]" value="{{country.id}}">{{country.country}}</option>
</select>
答案 0 :(得分:0)
ng-options可帮助您将对象绑定到选择值。
尝试这样的事情:
HTML
{{usercountry}}
<select ng-options="country as country.country for country in countries" ng-model="usercountry"></select>
angularJS
$scope.countries = [
{id: 0, country: "Italy"}, {id: 1, country: "Greece"}
];
$scope.usercountry = $scope.countries[0];
如果您还有其他问题,请告诉我们:)