How To Set Html Select Value With Angular 2
I want to set selected value from an HTML dropdown from a Angular2 component. I'm failing to see if this should be working or I need something more complex HTML
Solution 2:
This should work like you did. Notice that could put your select
within a form element:
<form><selectclass="form-control"id="role" [ngModel]="SelectedRole"><option *ngFor="#option of Roles" [value]="option.Value"> {{option.Text}}</option></select></form>
See this plunkr: https://plnkr.co/edit/J1aVclVcjJPqm1Qx9j0j?p=preview.
Solution 3:
It's hard to find answers for particular angular versions... so while searching for this issue while using a more recent version (angular 4.4.5), I've stumbled upon this thread. However none of the answers work for me so here is my solution for newer versions, in case someone else might stumble upon this thread too :-)
<selectclass="form-control" [(ngModel)]="size"name="sizeValue" #sizeValue="ngModel"><option *ngFor="let size of sizes" [value]="size">{{size}}</option></select>
In particular this part: name="sizeValue" #sizeValue="ngModel" on the select element.
Post a Comment for "How To Set Html Select Value With Angular 2"