Angularjs 选择选项 ng 选择为分配值选择空白选项

Angularjs select option ng-selected select blank option for assign value

本文关键字:选择 选项 空白 分配 ng Angularjs      更新时间:2023-09-26

在我的控制器中:

$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>

角度简斯

$scope.countries = [
    {id: 0, country: "Italy"}, {id: 1, country: "Greece"}
];
$scope.usercountry = $scope.countries[0];

如果您还有其他问题,请告诉我:)