The dropdownlist is white/empty. I would like to put a title for example Choose
.
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" 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
CodePudding user response:
Use this -
<select [(ngModel)]="type" name="type" 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
CodePudding user response:
<select [(ngModel)]="type" name="type" 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>