0

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,

1
  • Can you post your fullcode first? or create demo link
    – Just code
    Commented Jan 10, 2019 at 9:31

3 Answers 3

2
<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

3
  • Thank you. You saved my day. Commented Jan 10, 2019 at 9:34
  • @PawanTiwari Im glad it solves the issue. Consider marking this answer as accepted. Thanks! Commented Jan 10, 2019 at 9:35
  • How to verify a file name format in angular. My format is like ACMTTL_01_##date##~ddMMyyyy_HHmmss##date##~ Commented Jan 10, 2019 at 11:33
1

set the interfacengmodel as empty string

public interfacengmodel: UrType = "";
0

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.