3
Leave a Reply

avatar
3 Comment threads
0 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
1 Comment authors
Jason Recent comment authors
  Subscribe  
newest oldest most voted
Notify of
Jason
Guest
<select class="form-control selectpicker" #select (change)="changeTower(select.value)" [(ngModel)]="_selectedTower">
  <option value="{{tower._id}}" *ngFor="#tower of _towers;">Tower {{tower.name}}</option>
</select>  

changeTower(id) {

    //id is the selected value
}

Jason
Guest

You need to use ngValue this way for your options:

<select class="form-control selectpicker" (change)="changeTower()" [(ngModel)]="_selectedTower">
  <option [ngValue]="tower._id" *ngFor="#tower of _towers;">Tower {{tower.name}}</option>
</select> 

See this plunkr: https://plnkr.co/edit/UC5iYQUIFIrQMNeYbSQy?p=preview.

Jason
Guest

If _selectedTower is referring to an object instead of a primitive value (same for _towers – array of objects instead of primitive values) then use ngValue instead of value

<select class="form-control selectpicker" (change)="changeTower()" [(ngModel)]="_selectedTower">
  <option [ngValue]="tower" *ngFor="let tower of _towers;">Tower {{tower.name}}</option>
</select>