ionic how to get the click event on oktext

Viewed 732

I have a select button on ionic that has two options okText and cancelText, my problem is that when I click the okText, my menu closes which is intended for this attribute. However, I would like to know how do I work it via click events. This is my code:

<ion-select okText="Okay" cancelText="Dismiss">
  ...
</ion-select>

I would like to figure out how do I push another page when I declare a function in my .ts file.

2 Answers

You can use ionCancel to trigger cancel click event and ionChange trigger ok click event.

Example:

HTML

<ion-select [(ngModel)]="employee" 
    (ionChange)="onModelChange()"
    (ionCancel)="onCancelClick()">

   <ion-option 
       *ngFor="let employee of employees" 
       [value]="employee"></ion-option>
  </ion-select>

TS

export class ExamplePage {

  employees = ['A', 'B', 'C', 'D'];
  employee;

  constructor() {

    this.employee = this.employees[0];
  }

  onModelChange() {

    console.log(this.employee);
  }

   onCancelClick () {
    console.log('handle onCancelClick');
  }

}

You can use below methods for cancel click event and ok click event.

<ion-select (cancel)="onCancelClick()" (change)="onOkClick()">
   ...
</ion-select>
Related