现在select是空白的,我认为angular默认添加了它。我希望默认为美国,但是我试过ng-selected="country.name == 'American'"
它不起作用?
我的DOM
<select name="country" ng-model="user.country"
ng-options="country.name for country in country_list" >
{{name}}
</select>
答案 0 :(得分:0)
您可以执行此操作,ng-init="value='American Samoa'"
这将在下拉列表中设置默认值
<select ng-model="value" ng-init="value='American Samoa'" ng-options="code.name as code.name for code in country_list">
</select>
<强> DEMO 强>
答案 1 :(得分:0)
答案 2 :(得分:0)
您的代码无法正常工作的原因是:
ng-options="country.name for country in country_list"
据我了解,此处的值为{name: 'Afghanistan', code: 'AF'}
而不是Afghanistan
或AF
。
你应该尝试这样的事情:
ng-options="country.code as country.name for country in country_list"
此值为AF
,您可以使用ng-init
将其设置为
user.country = 'AS'
答案 3 :(得分:-1)
use something like this in your controller
$scope.user = {country:"American"}; //Default value to dropdown