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 display input message in Angular drop down list?

In my drop-down list, I would like to write: "Please select your country".

enter image description here

I added this line:

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

<option selected disabled value="">Please select your country</option>

But, I still have the same problem, nothing is displayed. The message "Please select your country" is not displayed.

enter image description here

Is this an Angular or HTML issue? Because I have no idea…

<div class="row row-cols-3 pt-3">
   <div class="col text-end">
      <!-- Country -->
      <label class="form-label">Country</label>
   </div>
   <div class="col-4">
      <select class="form-select" [(ngModel)]="search.country">
      <!-- Please select your country -->
      <option selected disabled value="">Please select your country</option>
      <option *ngFor="let country of countries" [value]="country.id">{{ country.name }} </option>
      </select>
   </div

>Solution :

You can set a default value to search.country as null in component.ts file.
And then set value as null to Please select your country option like below:

In component.ts file

search.country = null;

In HTML:

 <div class="col-4">
      <select class="form-select" [(ngModel)]="search.country">
      <!-- Please select your country -->
      <option selected disabled value="null">Please select your country</option>
      <option *ngFor="let country of countries" [value]="country.id">{{ country.name }} </option>
      </select>
   </div

Also try this way as well if not worked
<option selected [value]="null">Please select your country</option>

Hope this help. Thanks!

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