我想获得selectedIndex然后获取选择数据模型,然后我发现我可以直接获取所选数据模型Angular2 RC2 Select Option selectedIndex。但是,选项下的单击事件不起作用。
<select class="form-control selectpicker" #Code name="Code" [(ngModel)]="model.Code">
<option value="" selected="selected">--Please select--</option>
<option *ngFor="let x of Codes" [value]="x.Code" [selected]="x.Code == model.Code" (click)="searchWithCode(x)">{{x.Name}}</option>
</select>`
searchWithCode(code:any) : void {
this.model.Name1 = code.Name1;
this.model.Name2 = code.Name2;
}
答案 0 :(得分:0)
尝试在下拉列表中使用更改事件:
<select class="form-control selectpicker" #Code name="Code" [(ngModel)]="model.Code" (change)="searchWithCode($event)">
<option value="" selected="selected">--Please select--</option>
<option *ngFor="let x of Codes" [value]="x.Code" [selected]="x.Code == model.Code" >{{x.Name}}</option>
</select>