Flipper Flipper - 8 months ago 35
Javascript Question

Angular - Default option of select not showing in dropdown

I have a drpdown list. In my html I have this:

<select id="universitySel" ng-model="universityValue" ng-options="university._id for university in universities">
<option value="-1">Choose university</option>

I bind this dropdown from my collection. I want to show optional text as first element as you see above. First element is always empty. How do I do this?


Set the value to an empty string "":

<option value="">Choose university</option>

(from Angular's documentation:)

Optionally, a single hard-coded <option> element, with the value set to an empty string, can be nested into the element. This element will then represent the null or "not selected" option.