我有类似的东西
<ion-item formGroupName="Dealer">
<ion-label color="primary" stacked>{{"Select dealer" | translate }}:</ion-label>
<ion-select formControlName="Value" (ionChange)="getDealerName($event)">
<ion-option *ngFor="let dealer of dealerslist.Items" value="{{dealer.Value}}">{{dealer.Name}}</ion-option>
</ion-select>
</ion-item>
我需要的是
public getDealerName(){
alert(dealer.Name);
}
我知道在事件中我获得了价值,但我需要获得所选选项的名称? 我说得很简单,你可以理解,我不需要价值,我需要在选项
中显示的文字答案 0 :(得分:0)
您可以按照以下方式执行此操作,
<ion-select (ionChange)="getDealerName()" [(ngModel)]="getSelectedValue">
<ion-option *ngFor="let some of someItems" value="{{some.name}}"> {{some.value}} </ion-option>
</ion-select>
并在组件中
getDealerName(){
console.log(this.getSelectedValue);
let term = this.someItems.filter(person => person.name ==this.getSelectedValue );
alert('id is '+this.getSelectedValue);
alert('value is '+term[0].value);
console.log(event);
}
<强> STACKBLITZ DEMO
强>
答案 1 :(得分:0)
没有双向数据绑定:
<select (change)="onChange($event.target.value)">
<option *ngFor="let i of datalist">{{i}}</option>
</select>
onChange(datalistValue) {
console.info(datalistValue);
}
对于双向数据绑定,请分隔事件和属性绑定:
<select [ngModel]="modalvalue" (ngModelChange)="onChange($event)">
<option [value]="i" *ngFor="let i of datalist">{{i}}</option>
</select>
export class Myapp{
devices = 'one two three'.split(' ');
modalvalue= 'two';
onChange(newValue) {
console.log(newValue);
this.modalvalue= newValue;
// ... do other stuff here ...
}