Pawan Tiwari
Pawan Tiwari

Reputation: 537

set default value on drop down in angular 6

I want to set a default value in my dropdown, but it seems I'm not able to do so.

<div class="form-group"> 
    <select id="interfaceType" (ngModelChange)="onChange($event)" [(ngModel)]="interfacengmodel" #interfaceType="ngModel"
    name="interfaceType" class="form-control" required  >
        <option value="" disabled selected>Choose Interface Name</option>
        <option *ngFor="let interface of interfaceList" [value]="interface.interfaceName">{{interface.interfaceName}}
        </option>
     </select>
     {{interfaceLocation}}
  </div>

I'm new to angular.
Thanks,

Upvotes: 0

Views: 6831

Answers (3)

Ved_Code_it
Ved_Code_it

Reputation: 774

set the value of property interfacengmodel that you want to selected as default

Upvotes: 0

Sachila Ranawaka
Sachila Ranawaka

Reputation: 41445

set the interfacengmodel as empty string

public interfacengmodel: UrType = "";

Upvotes: 1

Antoniossss
Antoniossss

Reputation: 32535

<select id="interfaceType" (ngModelChange)="onChange($event)" [(ngModel)]="interfacengmodel"

Just set the default value (whatever it is ) to interfacengmodel in your component and it will become selected

Upvotes: 2

Related Questions