Skip to content

Instantly share code, notes, and snippets.

@dpedro
Created March 2, 2017 21:48
Show Gist options
  • Save dpedro/f89ff77e5de9d6aae561909be1cc7bba to your computer and use it in GitHub Desktop.
Save dpedro/f89ff77e5de9d6aae561909be1cc7bba to your computer and use it in GitHub Desktop.
Set selected item via ngModel
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