Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to put a title in a drop down list?

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

>Solution :

Use this –

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

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading