Pass ion-select-option to function - Ionic 4

本秂侑毒 提交于 2019-12-22 08:55:45

问题


I have this Ionic version 4 code that is simply trying to take a the selected value and pass it to a function in it's component:

<ion-item>
<ion-label>Convert Currency</ion-label>
<ion-select [(ngModel)]="currency">
<ion-select-option *ngFor="let c of currencyData" [value] = "c" >{{c.text}}</ion-select-option>
</ion-select>

I tried onChange but that is apparently not in version 4.


回答1:


You are looking for ionChange

  <ion-select [(ngModel)]="currency" (ionChange)="yourFunction($event)">



回答2:


you can use ionChange to pass the selected value as follow :

     <ion-select (ionChange)="checkValue($event)"  interface="popover" 
      placeholder="Select One" >
        <ion-select-option *ngFor="let c of currencyData" [value]="c"> 
       {{c.text}}</ion-select-option>
 </ion-select>

In your typeScript:

checkValue(event){ console.log(event.detail.value)}


来源:https://stackoverflow.com/questions/53551889/pass-ion-select-option-to-function-ionic-4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!