2017-05-04 45 views
0

角版本设置选择的值 - 1.2.28(传统,挂起升级)AngularJS - 从模型

我想设置为我通过模型值选择元素选择的值。

在我的控制器我有下面的行;

$scope.customer.country = 'GB'; 

而在我看来我有下面的select元素;

<select 
    ng-model="customer.country" 
    ng-options="country as country.name for country in countries track by country.alpha2"> 
</select> 

我期待,我应该有与“国标”的alpha2值国家一个对象,它会在默认情况下渲染选择。

但是实际行为是默认选中的空白选项。

如何通过模型(ng-model)值设置默认选定值?

+0

我以为你有重新绑定初始化对象后下拉? –

回答

2

看来初始化错误

$scope.customer.country = 'GB'; 

您有数组相同的对象被绑定到初始化(国家

应该像

$scope.customer.country = $scope.countries[0]; 

CodePen

+0

这是否解决你的问题? – mastermind