[英]default option in select box - angular js
<select name="country" id="countries" ng-options="country.name for country in countries track by country.id" style="font-size:13px;" ng-model="sel_country"
ng-change="set(sel_country)" >
<option>--</option>
</select>
// countries object
$scope.countries = [{name: 'UNITED KINGDOM', id: 1 },{name: 'AUSTRIA', id: 2}];
如何使用上述代码在选择框中显示默认选项?
我想您想将“-”作为默认值。
更改
<option>--</option>
至
<option value="">--</option>
<select name="country"
id="countries"
ng-options="country.name for country in countries track by country.id"
style="font-size:13px;"
ng-model="sel_country"
ng-change="set(sel_country)" >
<option value="" disabled selected>--</option>
</select>
Option-1 :在您的<option>
标记内使用value=""
<select name="country" id="countries" ng-options="sel_country as country.name for country in countries track by country.id" style="font-size:13px;" ng-model="sel_country[0]"
ng-change="set(sel_country)" >
<option value="">-select-</option>
</select>
选项2 :将ng-init
与ng-model
<select ng-init="sel_country = countries[0]" name="country" id="countries" ng-options="sel_country as country.name for country in countries track by country.id" style="font-size:13px;" ng-model="sel_country"
ng-change="set(sel_country)" >
<option>-select-</option>
</select>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.