How can I capture the click event on the oktext in Ionic?

When using Ionic, I have a select button with options for okText and cancelText. The issue I am facing is that when I click on okText, the menu closes as expected due to this attribute. However, I am interested in implementing it through click events. Below is my code snippet:

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

I am looking for a way to navigate to another page when a function is declared in my .ts file.

Answer №1

To activate the cancel click event, you can utilize ionCancel, and to trigger the ok click event, you can use ionChange.

For instance:

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');
  }

}

Answer №2

There are a couple of ways to handle cancel and ok click events in Ionic select elements.

<ion-select (cancel)="handleCancelClick()" (change)="handleOkClick()">
   ...
</ion-select>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Angular. The MatSelectionListChange event is returning an undefined value

I am attempting to retrieve the value of a changed element in a list, but I always get an undefined value while the checked property seems to be correct. HTML <div> <mat-selection-list #costUnits [(ngModel)]="selectedCostUnits" ...

Typescript: Transforming generic types into concrete types

I am utilizing a Generic type type GenericType = { [key: string]: { prop1: string, prop2?: string, prop3?: number, }, }; The purpose of the Generic type is to assist in constructing / validating a new object that I have created. const NewO ...

Where can I find the @types for a specific lodash package?

Seeking to utilize a specific function from lodash - assignin. I have successfully installed lodash.assignin and incorporated it into my project: import assignIn = require('lodash.assignin'); However, when compiling, an error occurs: "error TS2 ...

Duplicating an Angular 2 reactive form without retaining the original reference

I am facing a challenge with my reactive form where I need to round certain values when the form is submitted, without altering their appearance on the page. To achieve this, I devised a method that generates a new form, rounds the specified values, and t ...

Top recommendations for steering clear of memory leaks in Angular

In my quest to identify and resolve potential memory leaks in my angular/spartacus application, I am currently focusing on locating any instances of "subscribe(..." calls within my code base for evaluation. I understand that the simplest solution is to us ...

Using a PNG image served from a Node.js server presents challenges when trying to use it as a marker in an Ionic

Currently, all of my images are being loaded from the server URL. This is how it looks in HTML: <img [src]="http://myserverurl.../image.png" /> Everything is working fine and I can see the images on the profiles. However, I am also using t ...

AgGrid Encounters Difficulty in Recovering Original Grid Information

After making an initial API call, I populate the grid with data. One of the fields that is editable is the Price cell. If I edit a Price cell and then click the Restore button, the original dataset is restored. However, if I edit a Price cell again, the ...

The map buttons are located underneath the map, and unfortunately, it seems that setting the map height to 100% using Angular is

Upon completing the creation and display of the map, an unusual occurrence is taking place where the map buttons ("Zoom rectangular, map settings, and scale bar") are appearing below the map as oversized icons. Additionally, there is a challenge when setti ...

Creating a model for a different user involves several steps that can be easily

Recently, I have been working on a project involving user interactions such as following other users and viewing their content. Using technologies like Prisma, GraphQL, and Nexus, I decided to create a following model today. The model structure is as follo ...

Error message: "Issue occurs when sending keys to protractor element's text value and

Having trouble running this code in Protractor as I keep encountering errors, and I'm unable to retrieve the value of the anpr_box_input text. Error message: ManagedPromise::871 {[[PromiseStatus]]: "pending"} failed - should have a valid license ...

Utilizing Angular to lazily load multiple routes/paths within a single module

I am currently in the process of setting up multiple horizontal routes (not nested) and grouping them into one lazy-loaded module. However, I am facing a challenge trying to properly match these routes within the lazy-loaded feature module itself. Below ...

Tips on handling communication between different feature modules each handling their own portion of the state

I am currently working on an Angular application that consists of multiple feature modules. My goal is to implement ngrx store in such a way that each module manages its own state. // app.module.ts ... imports: [ ... StoreModule.forRoot(reducers) ...

what is the best way to eliminate comments from nested arrays when using useReducer?

Can someone help me figure out how to use useReducer and useContext to manipulate global state? I specifically need to know how to delete comments using useReducer. Data Structures View the interface image here Sample Data Array export const listsData:IDa ...

Using redux action in the onPaginationChange function instead of setPaginationState in the given example for the TanStack table - is there a way to

Provided this sample Is there a way to utilize by dispatching a redux action rather than using useState - setPaginationState? onPaginationChange: state => dispatch(browseItemModalActions.setPagination(state)) An error is appearing in the console: ...

Assign a class to an Angular component's host element without any conditions

In my Angular project, I have a component where I need to apply a class unconditionally. To achieve this, the host property within the @Component decorator can be used: import { Component } from '@angular/core'; @Component({ selector: 'ap ...

What is the best way to keep an item from list A after it has been moved to list B using PrimeNg's drag and drop feature?

I am facing an issue with the drag and drop feature in PrimeNg. I have a container that contains both a table and an unordered list. My goal is to be able to drag an element from the unordered list and drop it into the table, while still retaining the drag ...

Using Angular's asyncValidator in conjunction with BehaviorSubject allows for real

Currently, I am working on developing an Angular form. Below is a snippet of my code where I am attempting to construct a multi-group form with an async validator. The scenario involves validating whether a number exists in a specific list. In a real-worl ...

"Exploring the insertion of a line break within the modal body of an Angular application

Is it possible to create a modal for error messages with multilined body messages without altering the modal template? Any assistance would be greatly appreciated. <div class="modal-body" > <p *ngIf="!_isTranslatable">{{_modalBody}}</p&g ...

Apply a border to the div that has been selected

I have a tool for storing information and I am using *ngFor to display each instance in a line. Is there a way to add a border when clicking on a line? The border should only appear on the clicked line, disappearing from the previous one if another line i ...

What could be the reason behind Typescript's unexpected behavior when handling the severity prop in Material UI Alerts?

Trying to integrate Typescript into my react project and encountering a particular error: Type 'string' is not assignable to type 'Color | undefined'. The issue arises when I have the following setup... const foo = {stuff:"succes ...