<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}];
如何使用上面的代码在选择框中显示默认选项?
答案 0 :(得分:0)
我想你想要“ - ”作为默认值。
变化
<option>--</option>
到
<option value="">--</option>
答案 1 :(得分:0)
<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>
答案 2 :(得分:0)
选项-1 :在value=""
代码中使用<option>
<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>