You can prefill a valid option by setting the ng-model
to an item from the collection.
However if you set it to an item that is not in that collection your ng-model
will remain set but the item will not appear in the dropdown options, or appear to be visually set.
The final option that ive done in the past is similar to yours. However i found that even when the user had selected an option that select option
selection was still available. Adding an ng-if
was the solution.
<select ng-model="selected3" ng-options="item for item in items">
<option value="" ng-if="!selected3">-- select field --</option>
</select>
This will show the element only if you havent selected an option. Using ng-if
and not ng-show/hide
means the element is removed from the DOM so you can't accidentally select it with CSS etc.
see fiddle: http://jsfiddle.net/hd89kds6/1/