我有一个下拉选择形式在角度2.
目前:当我选择一个选项时,选项名称将作为$event传入我的onChange函数
想要:当我选择一个选项时,我想将workout.id传递到我的onChange函数中.
我该如何实现呢?
@H_502_7@<select class="form-control" [ngModel]="selectedWorkout" (ngModelChange)="onChange($event)"> <option *ngFor="#workout of workouts">{{workout.name}}</option> </select>调节器
@H_502_7@onChange(value){ alert(JSON.stringify(value)); }
@H_502_7@<select class="form-control" [ngModel]="selectedWorkout" (ngModelChange)="onChange($event)">
<option *ngFor="#workout of workouts" [value]="workout.id">{{workout.name}}</option>
</select>
要么
@H_502_7@<select class="form-control" [(ngModel)]="selectedWorkout" (change)="onChange($event.target.value)"> <option *ngFor="#workout of workouts" [value]="workout.id" >{{workout.name}}</option> </select>