<select> placeholder with angular/bootstrap not working

I would like to have a select with a placeholder in angularjs with bootstrap. The solutions I have found do not work with angular

Here is my angular markup:

<select ng-model="myModel" 
     ng-options="p.name for p in ..."
     class="form-control list-selector required">
   <option value='' disabled selected>Please Choose</option>
</select>

If someone has a working solution…

thanks ๐Ÿ™‚

Here is Solutions:

We have many solutions to this problem, But we recommend you to use the first solution because it is tested & true solution that will 100% work for you.

Solution 1

You need to add an empty option to your select:

<option value="">- Please Choose -</option>

Here is a working example: http://jsfiddle.net/DianaNassar/FShdc/

Solution 2

For Angularjs Versions and reactive forms , if you are using ngValue to bind values in options , the following type of solution will work:

<option value='' selected ng-value="null">Please Choose</option>

For Angular 2+ Versions something like this will work-

<select class="form-control"
    formControlName="roomType" 
    (change)="changeRoomType($event)">
    <option [ngValue]="null" selected>Room Type</option>
    <option *ngFor="let room of roomTypes" [ngValue]="room">{{room}}</option>    
    </select>

For reference, check this link out-https://netbasal.com/angular-quick-tip-how-to-show-a-placeholder-in-select-control-bab688f98b98

Note: Use and implement solution 1 because this method fully tested our system.
Thank you ๐Ÿ™‚

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply