OnLearn OnLearn - 2 months ago 14
HTML Question

HTML selection automatically selects first entry

I have the following code:

<select #typ class="input" (change)="changeIndex(typ.value)">
<option *ngFor="let creation of creationComponent>{{creation.name}}</option>
</select>


If I start the application the selection has automatically selected the first option. But I don't want that. Why is this and how can I fix it?

Answer Source

The trick is setting an empty option with display:none.

<select>
  <option style="display:none"></option>
  <option>1</option>
  <option>2</option>
</select>