html - How to implement dropdown menu as per below requirements in angular2 -
by default want set value in dropdown this: {{getteamname(employee.team)}}
, bind value {{team.$value}}
.
<div class="form-group"> <label for="team">designation</label> <select [(ngmodel)]="selectedvalue" [ngmodeloptions]={standalone:true}"> <option *ngfor="let team of teams">{{team.$value}}</option> </select> </div>
function:
getteamname(key) { let result = this.teams.filter(item => item.$key == key); if (result.length > 0) { return result[0].$value; } return ''; }
you directly consider binding emplyee.team
pre-populate team
object in ngmodel
& populating team
value inside dropdown use [ngvalue]="team"
on option level. not sure team.$value
, assumed want display team.name
.
<div class="form-group"> <label for="team">designation</label> <select [(ngmodel)]="employee.team" [ngmodeloptions]={standalone:true}"> <option [ngvalue] *ngfor="let team of teams">{{team.name}}</option> </select> </div>
Comments
Post a Comment