1

I am trying to preselect (set as default) value from Angular 5 drop down.

There are three values and I am trying to set the second one with this code but it doesn't work. I can't make any changes in the component, only in the template.

<select [(ngModel)]="declaration.media" name="media" (change)="onChangeMedia()" class="form-control form-control-sm" required>
    <option *ngFor="let media of mediaArray" value="{{media.value}}" selected = "{{media.value == '02'}}">{{media.text}}</option>
</select>

UPDATE: if I remove [(ngModel)] then it works, but no two way binding.

Nenad Bulatović
  • 7,238
  • 14
  • 83
  • 113
  • Possible duplicate of [Angular 2 Dropdown Options Default Value](https://stackoverflow.com/questions/35978450/angular-2-dropdown-options-default-value) – baao Jun 22 '18 at 11:15

1 Answers1

0
<select>
  <option value="" selected disabled hidden>Choose here</option>
  <option value="1">One</option>
  <option value="2">Two</option>
  <option value="3">Three</option>
  <option value="4">Four</option>
  <option value="5">Five</option>
</select>
laxmi
  • 1
  • 2
    Can you please add any description how this fragment of plain HTML code can help to solve the OP's problem with setting of default select value in Angular 5? – cgrim Sep 27 '18 at 10:32