-1

The dropdownlist is white/empty. I would like to put a title for example Choose.

illustration

I tried adding <optgroup label="Choose">/ </optgroup> but I want the title to be in the input before that the user clicks on the dropdown.

How to do this?

<select [(ngModel)]="type" name="type" class="form-select" style="width: 10%">
  <optgroup label="Choose ">
    <option value="Y">Yes</option>
    <option value="N">No</option>
  </optgroup>
</select>

Here is a reproduction on Stackblitz.

Thanks

mohciniya
  • 3
  • 3

2 Answers2

0

Use this -

<select [(ngModel)]="type" name="type" class="form-select" style="width: 10%" placeholder="Choose">
    <option disabled selected>Choose</option>
    <option value="Y">Yes</option>
    <option value="N">No</option>
</select>

This answer is copied partially from this answer answered by gam6itko

Archit Gargi
  • 634
  • 1
  • 8
  • 24
0
<select [(ngModel)]="type" name="type" class="form-select" style="width: 10%" placeholder="Select a value">
  <option selected disabled value="">Select a value</option>
  <option value="Y">Yes</option>
  <option value="N">No</option>
</select>
Parth
  • 31
  • 7