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

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -