0

I am trying set default selected object for select option in angular 6.But it's not working

<select name="editUserType" class="form-select" id="editUserType" [(ngModel)]="updateModel.userType">
    <option value="" selected disabled>Select User Type</option>
    <option *ngFor="let userType of userTypeList"  [selected ]="userType.code == updateModel.userType.code"  [ngValue]="userType">{{userType.description}}</option>
</select> 

userType is a object I want to, when I load web page set default object for select option.

Shalika
  • 1,457
  • 2
  • 19
  • 38
  • 1
    [(ngModel)]="updateModel.userType",since usertype is object no value will be set.I would suggest you to hardcode some value here and check like [(ngModel)]="Shalika" and for your information you cannot bind object only primitive types are possible. – Hameed Syed Jan 24 '19 at 06:05
  • Can you provide StackBlitz? – Prashant Pimpale Jan 24 '19 at 06:18
  • Click on the link below this might help you. https://stackoverflow.com/a/56346652/9292877 –  May 28 '19 at 16:40

1 Answers1

1

set the default value from the component

constructor(){
  this.updateModel.userType = ""
}
Sachila Ranawaka
  • 39,756
  • 7
  • 56
  • 80