拥有下一个选择器:
<select
ng-model="vm.selectedUserState"
ng-options="u as u.Group disable when u.Obsolete for u in vm.UserStates">
</select>
当加载页面并禁用当前状态代码(Obsolete为true)时,我看到空选择,我如何解决这个问题(即使禁用某个项目也预先选择一个合适的选项)
答案 0 :(得分:1)
您的ng-model
可能在加载时未定义,如果您希望在控制器中设置初始选定项目ng-model
vm.selectedUserState = vm.UserStates[selectionKeyName]
<强>更新强> 看看Angular来源我认为不可能:
if (option && !option.disabled) { //Skips if it's disabled <----
if (selectElement[0].value !== option.selectValue) {
removeUnknownOption();
removeEmptyOption();
selectElement[0].value = option.selectValue;
option.element.selected = true;
option.element.setAttribute('selected', 'selected');
}
} else {
if (value === null || providedEmptyOption) {
removeUnknownOption();
renderEmptyOption();
} else {
removeEmptyOption();
renderUnknownOption();
}
}
答案 1 :(得分:0)
解决了添加额外检查的问题
<select
ng-model="vm.selectedUserState"
ng-options="u as u.Group disable when (u.Obsolete && vm.selectedUserState.Code !== u.Code) for u in vm.UserStates">
</select>