Issue with (click) event not being detected on most elements throughout Ionic 4 webpage

BACKGROUND:

After working perfectly for some time, all the click events in my Ionic app suddenly stopped functioning. I have two floating action buttons that used to trigger a JS alert popup and open a modal window, but now they are unresponsive.

The only elements with functional click events now are my ion-tab-buttons.

WHAT I HAVE TRIED/TESTED:

  • I attempted to unwrap these elements from ion-items and ion-lists, yet the issue persisted.

  • I also tried using a simple ion-button as a replacement, but that didn't solve the problem either.

  • Moving the ion-button outside of the card element just below the opening ion-content tag did not make any difference.

  • Similarly, relocating the ion-button outside of the ion-content; just above the tabs, had no effect on the click events.

Any assistance would be greatly appreciated.

contact.page.html

<ion-header class="navbar">
  <div class="icons">
    <ion-buttons slot="start">
      <ion-menu-button color="tertiary"></ion-menu-button>
    </ion-buttons>
    <img src="assets/logo.png" />
  </div>
</ion-header>


<ion-content text-center>

  <ion-card>
    <ion-card-header>
      <ion-card-title>Contact Us</ion-card-title>
      <ion-card-subtitle>BOUTIQUE SOLICITORS</ion-card-subtitle>
    </ion-card-header>
    <br>
    <ion-card-content>

      <ion-label><b>Head Office: Wembley</b>
        <br>
        Boutique Immigration Solicitors, 10th Floor Tower, 1 Olympic Way, Wembley, Middlesex HA9 0NP
        DX: 51165 Wembley Park
        We are located just 5 minutes from Wembley Park Station. There is a car park behind our office.
      </ion-label>

      <br>
      <br>

      <ion-list text-left>
        <ion-item>
          <ion-label>Call us on 0800 3881 0211</ion-label>
          <ion-fab-button color="secondary" slot="end" size="small" (click)="callAlert()">
            <ion-icon name="call"></ion-icon>
          </ion-fab-button>
        </ion-item>
        <ion-item>
          <ion-label>Email at <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="08696c656166486a677d7c61797d6d7b6764616b617c677a7b266b67267d63">[email protected]</a></ion-label>
          <ion-fab-button color="secondary" slot="end" size="small" (click)="modalEmail()">
            <ion-icon name="mail"></ion-icon>
          </ion-fab-button>
        </ion-item>
      </ion-list>
    </ion-card-content>
  </ion-card>
</ion-content>

<ion-tabs>
  <ion-tab-bar slot="bottom">
    <ion-tab-button (click)="about()">
      <ion-icon name="information-circle-outline"></ion-icon>
      <ion-label>About Us</ion-label>
    </ion-tab-button>
    <ion-tab-button (click)="dashboard()">
      <ion-icon color="blue" name="home"></ion-icon>
      <ion-label>Dashboard</ion-label>
    </ion-tab-button>
    <ion-tab-button class="activeTab">
      <ion-icon name="contacts"></ion-icon>
      <ion-label>Contact Us</ion-label>
    </ion-tab-button>
  </ion-tab-bar>
</ion-tabs>

contact.page.ts

import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router'
import { CallNumber } from '@ionic-native/call-number/ngx';
import { ModalController, AlertController } from '@ionic/angular';
import { EmailPage } from '../email/email.page';

@Component({
  selector: 'app-contact',
  templateUrl: './contact.page.html',
  styleUrls: ['./contact.page.scss'],
})
export class ContactPage implements OnInit {

  constructor(private router: Router, private callNumber: CallNumber, private alertController: AlertController, private modalController: ModalController) { }

  ngOnInit() {
  }

  about() {
    console.log('clicked about')
    this.router.navigate(['members/menu/about'])
  }

  dashboard() {
    console.log('clicked dashboard')

    this.router.navigate(['members/menu/dashboard'])
  }

  async callAlert() {
    console.log('method executed')
    const callAlert = await this.alertController.create({
      message: "Are you sure you want to call Boutique Solicitors?",
      buttons: [{
        text: "Cancel",
        role: "cancel"

      },
      {
        text: "Call",
        handler: () => {this.callBS()}
      }
    ]
    });
    callAlert.present()

  }

  async callBS() {

    this.callNumber.callNumber("07847948252", false)
  .then(res => console.log('Launched dialer!', res))
  .catch(err => console.log('Error launching dialer', err))
  }

  async modalEmail() {
    const modal = await this.modalController.create ({
      component: EmailPage
    });
    modal.present();
  }

}

Answer №1

After some trial and error, I managed to solve the problem on my own. It turns out that placing ion-tabs outside of the 'ion-content' at the bottom causes an issue where their "click-zone" extends across the entire page when inspecting with Chrome Dev Tools. Surprisingly, adjusting the "z-index" css property does not help in resolving this issue.

The solution is to enclose the ion-tabs within an ion-toolbar, positioned below the closing 'ion-content' tag. This adjustment confines the click-zone to the height of the ion-toolbar, effectively fixing the problem. Now, all other elements on the page can trigger (click) events as intended. Additionally, this resolves any issues with tabs interfering with page scrolling.

I have tested this fix on both Android and iOS platforms.

Goodbye for now!

Answer №2

It seems the solution provided above is not accurate. There appears to be a misconception regarding the functionality of tabs as mentioned by the original poster (OP). Tabs are designed to serve as full-page user interface components and should not be embedded within other pages or components. In essence, they should be the primary content on a page.

<ion-tabs>

  <ion-tab-bar slot="bottom">
    <ion-tab-button tab="tab1">
      <ion-icon name="triangle"></ion-icon>
      <ion-label>Tab 1</ion-label>
    </ion-tab-button>

    <ion-tab-button tab="tab2">
      <ion-icon name="ellipse"></ion-icon>
      <ion-label>Tab 2</ion-label>
    </ion-tab-button>

    <ion-tab-button tab="tab3">
      <ion-icon name="square"></ion-icon>
      <ion-label>Tab 3</ion-label>
    </ion-tab-button>
  </ion-tab-bar>

</ion-tabs>

This implementation ensures that the tabs are responsible for rendering the nested content, allowing events to function correctly as intended.

Answer №3

After some trial and error, I managed to find the solution on my own. It turns out that when ion-tabs are positioned outside of the 'ion-content' at the bottom, there is a strange issue where their "click-zone" covers the entire page and appears in front of all other elements when inspected with Chrome Dev Tools. Interestingly, using the "z-index" CSS property does not fix this problem.

The workaround is to encapsulate the ion-tabs within an ion-toolbar, located below the closing 'ion-content' tag. This adjustment confines the click-zone to the height of the ion-toolbar, effectively resolving the issue. Now, all other elements on the page can trigger click events as expected. Additionally, this approach addresses any difficulties with tab navigation hindering page scrolling.

I confirmed this solution works seamlessly on both Android and iOS platforms.

Farewell for now!

Happy to help! That's exactly what I was looking for. Thanks!

Answer №4

The response provided by @mhartington is spot on. When working with Angular, it's important to have tabs set up as the main page that loads additional pages as child modules within the tabs-routing.module.ts file.

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

Sharing data between React JS components Passing information between different components in React JS

My NavBar.js component contains login information for the logged-in user. It displays "Welcome" along with the user details when the user is logged in. Now, I want to replicate this functionality in the ProductList.js component so that when a user posts a ...

Any suggestions for a more effective method of managing authentication in Angular2 rc3 besides using guards?

After upgrading to router 3.0.0-alpha.8, I encountered a hurdle with authentication in my existing Angular2 app. Previously, I handled login/authentication by extending the RouterOutlet with an AuthRouterOutletDirective. This allowed me to easily check if ...

Exclude file from the source directory in Webpack configuration

My Angular project is set up with webpack for compilation, but I am facing an issue with separate main files for different environments (main.dev-only.ts, ...). Whenever I try to compile, I encounter the following error: ERROR in : Type in is part of the ...

Using jQuery's .grep() method on an array will only return the final digit

Could someone help me understand the behavior of jQuery's .grep() method? I'm creating a jQuery object array based on the names of these elements: <div class="small1 other">S1</div> <div class="small2">S2</div> <div c ...

Angular application making a $http.post request to change the date to a UTC date

I encountered an issue while trying to send data to my REST api that includes a date parameter. During debugging, I noticed that my date parameter is a JS Date object with the correct date in my timezone: Tue Apr 04 2017 00:00:00 GMT+0530 However, once it ...

The ever-changing world of list items with dynamic editions

One of my tasks involves displaying a list of elements through the ng-repeat directive. Each element is contained within its own div block. My goal now is to enable editing for each block, so that when users click on an edit button, the content of the div ...

Ionic 3: Incorporating Baidu map functionality exclusively for web browsers

My current project with Ionic 3 involves incorporating the npm package angular2-baidu-map to display maps of China mainland. I have successfully obtained an API key for Baidu Maps (for the JS API), and the map functions perfectly in a browser (via ionic s ...

How to retrieve all the days of each month starting from a particular day with the help of momentJS in Angular

I am currently working on developing a custom day picker that will show all the days of the month in a calendar format, displaying them from Sunday to Saturday. Currently, I am only able to display dates from the 1st of the month onwards. https://i.sstati ...

Unraveling encrypted data from Java in Node.js: a step-by-step guide

Currently, I am working on converting Java lambda functions into JavaScript lambda functions. Specifically, I am focused on converting the encrypt and decrypt methods from Java to Node.js or JavaScript. So far, I have tried implementing this using the &apo ...

The TypeScript compilation is missing Carousel.d.ts file. To resolve this issue, ensure that it is included in your tsconfig either through the 'files' or 'include' property

While trying to build an Angular application for server-side execution, I encountered the following errors: ERROR in ./src/app/shared/components/carousel/interface/Carousel.d.ts Module build failed: Error: /home/training/Desktop/vishnu/TemplateAppv6/src ...

Using the SmartSheets API to Iterate Over a List to Determine the Variable of a Function

I have a group of numerical values listed below that are stored in a variable. [700000000084, 100000000051652, 8800000000000072, 280000000000004, 680000000000008, 880000000000006] My goal is to iterate through this list using the SmartSheets API to gathe ...

Facing issue in Angular 5 tutorial: Error encountered - module '@angular-in-memory-web-api' not found

While researching my issue, I came across a similar question related to angular2. However, the solutions provided were specific to angular2 or instructed me to run the same command that I am already using, prompting me to ask for help here. I am currently ...

Get the npm distribution package without the need to actually install npm

Is there a way to obtain an npm package without the need for running npm view XXX ... or installing node/npm? Specifically, I am attempting this process on a Linux operating system. ~UPDATE~ I now understand that I should have provided more details about ...

Tips for accessing various JSON objects from a JSON document

My task involves extracting specific information from a JSON file using AJAX and jQuery. The structure of my JSON data is as follows: "Footwear": { "Adidas": [ { "id" : 0, &q ...

unable to save the information to mongoDB

I've been attempting for the past 3 hours to save data from an HTML form to MongoDB using Node.js. When I click submit, it redirects to another page displaying the submitted data in JSON format, but it's not getting stored in the database. Here ...

Why can't we access res.locals.user in the ejs file?

Working with NODE JS In my project, I have a dashboard.ejs file and a .js file. I tried setting a variable in the js file to locals but I am unable to access it in the ejs file. The main functionality of my project is ensuring that the user logs in befo ...

Tips for Avoiding "TypeError: fetch failed" on Next.js Page Server Component While Retrieving Data from Spring Boot API

Working on a Next.js application has been quite challenging as I fetch data from my Spring Boot API within a Page server component. Unfortunately, my GitHub Action CI/CD pipeline has been encountering failures during the Docker image build process, specifi ...

The Design and Layout of a MEAN Stack Application

When creating a MEAN Stack app using the express-generator npm, everything worked perfectly but I found myself confused about the purpose of certain files. For instance: The package.json included this code snippet: "script":{"start": "node ./bin/www"} ...

How to Reload the Active Tab in Angular 5?

In my project, I have noticed that a listener in one of the tabs causes the entire tab to refresh, resulting in it displaying information from the first tab until I switch to another tab and then go back. 1) Is there a way to refresh only the current tab? ...

"Enhance your user experience with React-datepicker's seamless time selection

Is there a way to customize the react date picker to include seconds as well? I have looked through the documentation but couldn't find an option for selecting seconds. Any help or example would be appreciated, you can check out the input Time section ...