Unable to trigger click or keyup event

After successfully implementing *ngFor to display my data, I encountered an issue where nothing happens when I try to trigger an event upon a change.

Below is the snippet of my HTML code:

    <ion-content padding class="home">
      {{ searchString }}
      {{ selectedOption }}
      <ion-searchbar (keyup)="onKey(box.value)"></ion-searchbar>


      <ion-list radio-group>
        <ion-list-header>
          <span class="listHeader">Items</span><span class="pullRight">Showing 3 of 3</span>
        </ion-list-header>

        <ion-item *ngFor="let x of Options" (click)="changeSelection(x)">
          <ion-label>{{ x.displayName }}</ion-label>
          <ion-radio value="{{ x.id }}"></ion-radio>
        </ion-item>
      </ion-list>

</ion-content>

I was expecting the (click) event to execute and call the changeSelection method in the JavaScript file:

import {Component} from '@angular/core';
import {NavController} from 'ionic-angular';


@Component({
  templateUrl: 'build/pages/home/home.html'
})
export class HomePage {
    reportOptions;
    selectedOption;
    searchString;
    constructor(private navController: NavController) {

    this.Options = [    {
                                displayName: 'Test Option 1',
                                id: '1'
                            },
                            {
                                displayName: 'Test Option 2',
                                id: '2'
                            },
                            {
                                displayName: 'Test Option 3',
                                id: '3'
                            }
                          ];
    this.selectedOption = 'Hello';

    }

    changeSelection(x) {
        this.selectedOption = 'world';
    }
    onKey(value: string) {
        this.searchString= value;
    }

}

I can't seem to figure out what's missing here. Is there any specific import that I overlooked or something more complex at play?

Answer №1

It seems like you're facing an issue with correctly binding the elements to their respective properties using [(ngModel)].

For the ion-radio elements, make sure you have included the radio-group attribute.

<ion-list radio-group>

Don't forget to bind these radio buttons to the selectedOption property in your Component. By adding ngModel, the value of the selected radio button will be automatically assigned to the selectedOption. If you also want to capture the text from the radio button, use the ionSelect event:

<ion-radio value="{{ x.id }}" (ionSelect)="changeSelection(x)"></ion-radio>

Add the corresponding method in your component:

public changeSelection(x: any) {
    this.selectedOptionText = x.displayName;
}

Regarding the ion-searchbar, similarly, ensure that it is bound to a property in your component. Bind it to the searchString property using:

<ion-searchbar [(ngModel)]="searchString"></ion-searchbar>

If you need to execute some code when the blur event occurs, subscribe to one of the Output events from the ion-searchbar. For instance, to link the ionBlur event to the onBlur method, do as follows:

<ion-searchbar [(ngModel)]="searchString" (ionBlur)="onBlur()"></ion-searchbar>

You can check out a working example on Plunker showcasing your code in action.

Answer №2

If the changeSelection function was present in the code snippet you shared, it would be called upon. Currently, I do not observe its presence within your posted code.

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

Loading data from a remote source in an Angular 6 material table: A step-by-step guide

I'm currently puzzled by the usage of the material table schematic and am struggling to find a solution. It appears that the key aspect lies within the connect() method present in the datasource.ts file. Simply put, this.data is merely an array. / ...

Utilize the key types of an object to validate the type of a specified value within the object

I am currently working with an object that contains keys as strings and values as strings. Here is an example of how it looks: const colors = { red: '#ff0000', green: '#00ff00', blue: '#0000ff', } Next, I define a type ...

Interactive 3D model movable within designated area | R3F

I am currently facing a challenge in limiting the drag area of my 3D models to the floor within my FinalRoom.glb model. After converting it to tsx using gltfjsx, I obtained the following code: import * as THREE from "three"; import React, { useRe ...

Ways to retrieve data from response instead of subscription JSON in Angular 2/4

My Service : retrieveData(url,request) { return this.http.post(this.apiUrl+url,request).subscribe( (response) => {return response.json()} ); } My Component : ngOnInit() { this.data = this.dataService.retrieveData(&apos ...

Type inference and the extends clause in TypeScript 4.6 for conditional types

My focus was on TypeScript 4.7 when I created the following types: const routes = { foo: '/foo/:paramFoo', bar: '/bar/:paramFoo/:paramBar', baz: '/baz/baz2/:paramFoo/:paramBar', } as const; type Routes = typeof routes; ...

What is the best way to align text alongside icons using ng-bootstrap in Angular 8?

I have a set of four icons positioned next to each other, but I want them to be evenly spaced apart. I tried using the justify-content-between class, but it didn't work. How can I achieve this? I'm creating a Progressive Web App (PWA) for mobile ...

The ability to choose only one option in a checkbox within a grid view column

In my grid view, I have a checkbox in the last column. I am trying to ensure that only one row can be selected at a time. <tr *ngFor="let permit of PermitDetails" (click)="GoByClick(permit)"> <td style="text-align: center">{{permit.TVA_BAT ...

Angular unit tests do not trigger the QueryList.changes.subscribe() listener

I need to create popup containers based on the number of items received. The component works fine in dev and prod environments, but fails in unit tests because querylist.changes does not emit. As a workaround, I have to manually call querylist.notifyChange ...

Attempting to imitate a form using Angular 2's HTTP post functionality

I am working on an ionic2 application that requires authentication to be done on an existing PHP website and then execute certain requests within it. I do not have access to the source code of the website. Since I am using ionic2, CORS should not be an iss ...

What are the best practices for implementing jquery owlCarousel within an Angular 4 component?

I've included my 'carousel.js' file like this: $('#owl-carousel-1').owlCarousel({...}); and in carousel.component.html, I have: <div id="owl-carousel-1" class="owl-carousel owl-theme center-owl-nav home- carousel">....< ...

Tips for properly implementing an enum in TypeScript when using the React useState hook

What's the correct way to utilize my useState hook? I have this enum type: export enum Status { PENDING = 'pending', SUCCESS = 'success', ERROR = 'error', } And the useState hook: const [isValid, setIsValid] = use ...

No solution was found for implementing Airbnb TypeScript in React.js (Next.js) using ESLint

screenshot I encountered an issue where I couldn't locate the Airbnb typescript option in React JS (Next JS) within ESLint. Prior to this, I had installed Storybook and mistakenly clicked "yes" when prompted to migrate ESLint to Storybook. ...

typescript tips for incorporating nested types in inheritance

I currently have a specific data structure. type Deposit { num1: number; num2: number; } type Nice { num: number; deposit: Deposit; } As of now, I am using the Nice type, but I wish to enhance it by adding more fields to its deposit. Ultima ...

Issue encountered in NestJS/TypeORM: Unable to modify the property metadata of #<Repository> as it only has a getter method

When attempting to launch my nestjstutorial app, I encountered the following error message. The backend is connected to a PostgreSQL database. TypeError: Cannot set property metadata of # which has only a getter at EntityManager.getCustomRepository (D:&b ...

Oops! It seems like there has been an issue. The EnjoyHint is not

Encountered the following error message: https://i.stack.imgur.com/JL4l6.png The error in my code is within the line that initializes a new EnjoyHint object. Seeking assistance to resolve this issue. public initiate(stepName) { const steps = ...

The function formdata.has in Angular 5 is experiencing compatibility issues with the Internet Explorer browser

if (this.formData.has('Apple')) { this.formData.delete('Apple'); } I encountered an issue where I am receiving the following error message: "Object doesn't support property or method 'has'" when att ...

Utilizing internationalization and next/image in next.config.js alongside TypeScript

Currently, I am in the process of developing a miniature application using TypeScript within NextJS now that support for TypeScript comes standard in Next.js. Additionally, my aim is to integrate two recently introduced features: Image Component and Image ...

Angular - Utilizing nested arrays for efficient file uploading

I am currently working on building a file uploader using Angular. My goal is to be able to upload different types of files, with each button capable of uploading multiple files at once. However, I am running into an issue where the uploaded files are not b ...

How to link a selection choice to an option using Angular 13

Can anyone provide guidance on how to bind data with a select option in Angular? I've tried multiple approaches but haven't been successful in getting the data to display in the options. Any assistance would be greatly appreciated. Thank you in a ...

Implementing a dependent <select> within an HTML table is a useful feature to enhance user experience and organization of

I have set up a table with editable columns where values can be selected from a drop-down menu. I achieved this by using HTML select. The options in the 'Category tier 2' column are based on the selection made in the 'Category tier 1' c ...