2016-11-23 80 views
0

我有一个字段,其中的选项动态。现在我想在默认情况下显示字段中的第一个选项值。可以帮助某人。我们如何在<select>默认显示的第一个选项值显示动态值

<div class="col-lg-4"> 
<select name="trader" class="form-control" id="select" ng-model="$root.customerDetails.traderType" 
ng-options="traderTypeObj.description for traderTypeObj in traderTypes track by traderTypeObj.type" ng-required="true">     
    </select> 
    </div> 

感谢

回答

1

您正在使用错误的语法ng-model。它应该是ng-model="customerDetails.traderType"卸下摆臂的$根。

用于在选择框中设置默认值,使用ng-initng-init="customerDetails.traderType = traderTypes[0]"

<select ng-init="somethingHere = options[0]" 
     ng-model="somethingHere" 
     ng-options="option.name for option in options"> 
</select> 
相关问题