[英]Angularjs select option ng-selected select blank option for assign value
在我的控制器中:
$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>
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];
如果您还有其他问题,请告诉我:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.