click event on ion card

Attempting to handle a click event within an ion-card using Ionic 5.0.2 version has presented some challenges. Despite my efforts, I have not been successful in handling the event with the expected function. Here is a snippet of my code:

Dynamic card list home.page.html

<ion-card *ngFor="let jsons of json"  button (onclick)="greed($event)">
          <ion-item>
            <ion-avatar slot="start">
              <img src="http://icons.iconarchive.com/icons/papirus-team/papirus-status/256/avatar-default-icon.png">
            </ion-avatar>
            <ion-label>{{jsons.nombre_servicio}}</ion-label>
          </ion-item>

          <ion-card-content >
            <ion-grid>
              <ion-row>
                  <ion-col size="8" size-md>
                      {{jsons.serviciodescripcion}}
                    </ion-col>
                    <ion-col size="4">
                     <ion-chip>
                        <ion-icon name="pin"></ion-icon>
                        <ion-label>{{jsons.costoHora}}</ion-label>
                      </ion-chip>
                    </ion-col>
              </ion-row>
            </ion-grid>

          </ion-card-content>
        </ion-card>

In the above code snippet, I have a function named greed that is supposed to receive a value indicating which card was clicked. The corresponding module is shown below:

home.page.ts

import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { AlertController } from '@ionic/angular';
@Component({
  selector: 'app-home-home',
  templateUrl: './home-home.page.html',
  styleUrls: ['./home-home.page.scss'],
})
export class HomeHomePage implements OnInit {
  user: any;
  constructor(public httpClient: HttpClient, public alertController: AlertController, public router: Router) { }
  json : any;
  clicked: any;
  ngOnInit() {
    const token = 'top10';
    this.httpClient.get(`https://mydatabaseapi/servicios.php?&token=${token}`)
    .subscribe(async data => {
      if ( data == null) {
      } else {
       console.log(data);
       this.json = data;
      }
     }, error => {
      console.log(error);
    });
  }
  back() {
    this.user = history.state;
    this.router.navigate(['/menu/:user'], {state: this.user});
  }
  greed(obj: any) {
    console.log(obj);

  }
}

Despite trying various approaches, including using console.log("HI stackoverflow"); without any parameters, I have not been able to capture the click event. Any suggestions?

Answer №1

in place of

(onclick)="greed($event)"

opt for

(click)="greed($event)" 

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

best practices for data flow between components in React using hooks

I have successfully retrieved data from my database in the Recipes component. Now, I am attempting to pass this data into the RecipeList component. However, when I do so, only the bullet points are showing up in the RecipeList component and for some reas ...

Is there a way to transform a .pcm file to a wav file using node.js?

I'm working on a project that generates a pcm file from a stream and saves it after the stream finishes. Now, I am looking for a way to convert this .pcm file to a .wav or another audio format using an npm package. Can anyone suggest a solution or poi ...

The second attempt at an AJAX call is unsuccessful

I am currently developing a form that displays database results based on two entries: Automarke (brand) and Modell (model). You can view the entries here. The Modell dropdown dynamically changes based on the selected Automarke. Here is the code snippet I ...

using jquery to retrieve the current time and compare it

This is the code I currently have: var currentTime = new Date() var month = currentTime.getMonth() + 1 var day = currentTime.getDate() var year = currentTime.getFullYear() var hours = currentTime.getHours() var minutes = currentTime.getMinutes() aler ...

What is the process of nesting an array of objects within an existing object, and how can additional objects be added to the array if it already exists?

I have a JSON file named questions.json containing an array of objects structured like this: { "id": "2", "ques": "here is my second code ?", "quesBrief": "I can't seem to find it too.", "hashes": "#javascript , #goodlord", "author": "slowde ...

What is the procedure for controlling a Textfield in the Browser with a Java code?

I have an automation problem that I am trying to solve. The task involves accessing a specific webpage with two editable text fields and some other elements, extracting the content from these text fields using a Java program to filter keywords and generate ...

Updating a JSON array by including a new key-value pair using Javascript

Below is a json string that needs to be converted into a new Json Array: Raw Data: [ ["yrxqBHmPkNhZ60_eab97ebf-c2a3-40a5-972a-91597ad9a4ca_99371", "SUCCEEDED", "2023-08-31T21:59:31.325000+05:30", "2023-08-31T22:13:42.165000+05:30"], ["yrxqBHmPkNhZ ...

Creating synchronization mechanisms for events in JavaScript/TypeScript through the use of async/await and Promises

I have a complex, lengthy asynchronous process written in TypeScript/JavaScript that spans multiple libraries and functions. Once the data processing is complete, it triggers a function processComplete() to indicate its finish: processComplete(); // Signa ...

Implementing Ideone API functionality on Codeigniter with the use of ajax, javascript, and soapclient

I am new to using Codeigniter and I apologize if my question is basic. I found some code on this site: Working with IDE One API (Full project code available here) and I'm attempting to incorporate it into Codeigniter. I have been able to get it worki ...

Angular: displaying dates in a specific format while disregarding time zones

Is there a way to format date-time in Angular using DatePipe.format() without converting timezones, regardless of location? For instance, for various examples worldwide (ignoring time differences) I would like to obtain 07/06/2022: console.log('2022-0 ...

Module-alias cannot be resolved by esm

Currently, I am utilizing the combination of esm package and module-alias. However, it appears that esm is not recognizing module-alias's paths. This is how I am loading my server file: nodemon -r esm ./src/index.js 8081 At the beginning of my inde ...

What is the best way to make the button cover the entire width?

I have a Vuetify card with a layout where I am rendering some dynamic Vuetify components inside the card based on checkbox selection. These components can be a divider, a spacer, toolbar, or a button. However, I'm struggling to make the buttons span t ...

Utilizing raw queries in TypeORM with NestJS to enforce lowercase column names

Can anyone help me execute a query using nest/typeorm? I'm utilizing Typeorm's "InjectConnection" to run a raw query in my Postgres Database. The issue arises with the column user_roles_role.userId (note that I am specifying 'userId' i ...

Error in JavaScript: Uncaught TypeError - Unable to access the "left" property of an undefined object

This error is really frustrating and I've come across several inquiries regarding this console issue. It's not providing enough information in the chrome console for me to effectively troubleshoot. /** * Adjustment of dropdown menu positio ...

The useEffect hook in Next.js does not trigger a re-render when the route changes

I'm currently experiencing an issue with a useEffect inside a component that is present in every component. I've implemented some authentication and redirection logic in this component, but I've noticed that when using Next.js links or the b ...

What is the best way to remove headers and footers programmatically in print pages on Safari using JavaScript?

Struggling with eliminating the header and footer on print pages in Safari using JavaScript? While disabling the header and footer manually can be done through print settings in most browsers, my aim is to automate this process with code to ensure that use ...

interval-based animation

I'm trying to create a simple animation using setInterval in JavaScript. The goal is to make an image move from left to right. HTML: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"& ...

Accessing the variable's value within a separate if statement within the function

I have a function that retrieves data from JSON and passes it to render, but I had to include two different conditions to process the data. Below is the function: filterItems = () => { let result = []; const { searchInput } = this.state; c ...

What could be causing ng-submit to not successfully transmit data?

I'm currently going through this Yeoman tutorial, but I'm encountering some issues. The new todo is not being added to the $scope.todos as expected, and I'm struggling to identify the reason behind it. You can access the code here: Upon c ...

The issue of ExpressionChangedAfterItHasBeenCheckedError is a common problem faced by Angular

I have implemented a component loading and an interceptor to handle all requests in my application. The loading component is displayed on the screen until the request is completed. However, I am encountering an error whenever the component inside my router ...