Charlie Charlie - 1 year ago 40
Javascript Question

Changing disable flag in ng-options causes select to be unlselected

Example of the problem:

https://embed.plnkr.co/5MSJB9E7AMNDF5oZQJRR/

When that is loaded,

h
is selected even though its disabled. This is fine and expected.

Next, if you selected a non-disabled value, let's say
d
. That works.

But once you click the button to flip the
disable
boolean, the model gets set to
null
and the select loses what's selected.

You can even flip the boolean for the initially selected value to not be disabled and the value stays, but then flip it again and it gets lost.

Is this expected? It doesn't seem that this should happen to me since the first use case allows it to be selected.

Answer Source

I posted the same question in the Angular github issue tracker and found out this behavior is by design. For me, that was good enough and we'll come up with another way to do it.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download