2

Have the next selector:

<select
      ng-model="vm.selectedUserState"
      ng-options="u as u.Group disable when u.Obsolete for u in vm.UserStates">
</select>

when page is loaded and current status code disabled (Obsolete is true), i see empty selection, how i can fix this (pre-select an appropriate option even when an item is disabled)

3
  • so you can write? u as u.Group for u in vm.UserStates track by u.Obsolete=false Commented Feb 3, 2016 at 12:46
  • or like this: <select ng-model="vm.selectedUserState" ng-options="u as u.Group for u in vm.UserStates" ng-if="u.Obsolete"> </select> Commented Feb 3, 2016 at 12:48
  • @Saahon the code you've provided not work (using the second listing select does not appear at all) Commented Feb 3, 2016 at 14:05

2 Answers 2

1

Your ng-model is probably undefined on load, if you want an initial selected item set your ng-model in your controller

vm.selectedUserState = vm.UserStates[selectionKeyName]

update: Looking at the Angular source I don't think it's possible:

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();
  }
}
Sign up to request clarification or add additional context in comments.

1 Comment

no, im sure vm completely defined (if vm.selectedUserState is not obsolete (no disabled) all works properly)
0

Solved adding an addition check

<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>

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.