<select> with <option> does not set default option correctly #14916
Description
The Problem
The expected behavior of <select>
when using ngModel
is to create a default blank <option>
when none of the ngRepeat
ed options match the model, as noted in this issue. However, this seems to occur even when the model matches a valid option.
The Proof
Here is a demo of the bug. It seems the second select option defaults to the only option available, hence the bug does not appear. However, the other 3 examples demonstrate the bug. The first select demonstrates the bug in its simplest form. The third select option uses {{}}
in the ngSelected
directive to demonstrate that the expression does evaluate to true. The final select shows that the issue remains even when a timeout is used to switch the selected option programmatically.
What is Expected?
If ngSelected
evaluates to true, as it does in the sample code, the default empty <option>
should not be created. Instead, the dropdown should default to the option that matches the model.
Why?
If the model is set appropriately, obviously there is a default value that should be selected. Maybe the user is visiting this page to update data and the dropdown should be set to the value previously selected. For my use case, the dropdown is tied to the current page number and blank is not a valid page number.
Version/Environment
I am using version 1.4.9. I have tested this and seen the bug in both Firefox and Chrome.