Created
March 2, 2017 21:48
-
-
Save dpedro/f89ff77e5de9d6aae561909be1cc7bba to your computer and use it in GitHub Desktop.
Set selected item via ngModel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
You don't need to use [attr.selected]. | |
[(ngModel)]="user.role" is two-way data-binding, | |
it will select the matched option from your list if value is equal to user.role. And you can also use basic [value] | |
<select name="role" [(ngModel)]="user.role"> | |
<option *ngFor="let role of roles" [value]="role">{{role.name}}</option> | |
</select> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment