Javascript Angularjs-为不带ng选项的select设置默认值
我有一个经典的精选Javascript Angularjs-为不带ng选项的select设置默认值,javascript,angularjs,select,Javascript,Angularjs,Select,我有一个经典的精选 <select class="form-control" id="gender"> <option value="Male">Male</option> <option value="Female">Female</option> </select> 男性 女性 我想根据来自scope{{profile.gender}的变量设置selected值。当变量为阴性时,也将选择选项值。问题
<select class="form-control" id="gender">
<option value="Male">Male</option>
<option value="Female">Female</option>
</select>
男性
女性
我想根据来自scope
{{profile.gender}
的变量设置selected
值。当变量为阴性时,也将选择选项值。问题是我并没有性别选项,只有字符串,所以我需要匹配它并选择。有没有可能用简单的方法来做呢?你看不到这些选项,因为你实际上没有一个经典的选择。Angular使用其自己的ng选项覆盖经典select
如果您想获得男性/女性选项,只需使用ng options
上的硬编码列表即可:
性别:{{profile.Gender}}