Anil Mhaske
Anil Mhaske

Reputation: 31

Default select option selected in Angular

In the following code for an input element:

<select name="tshirtsize" [(ngModel)]="tshirtsize" class="form-control" 
        #tshirtRef="ngModel" required>
    <option *ngFor="let shirt of tShirtSize" [ngValue]="shirt"> 
        {{shirt.name}}
    </option>
</select>

How to show default option selected for user (ex. please select option) in Angular?

Upvotes: 1

Views: 102

Answers (1)

Sajeetharan
Sajeetharan

Reputation: 222720

You can add something like

<select name="tshirtsize" [(ngModel)]="tshirtsize" class="form-control" #tshirtRef="ngModel" required>
    <option [ngValue]="undefined" disabled  selected> Please select one option </option>
    <option *ngFor="let shirt of tShirtSize" [ngValue]="shirt">{{shirt.name}}</option>
</select>

Upvotes: 2

Related Questions