question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ion-slides not working in modal when ion-button is present in modal

See original GitHub issue

Bug Report

Ionic version:

[x] 4.0.1

Current behavior: On second opening of modal view with ion-slides and ion-button inside of modal template ion-slides becomes unresponsive, without ion-button everything is working correctly

Expected behavior: ion-slides should work correctly everytime modal is opened and it should not depend on other components in templates like ion-button

Steps to reproduce: Use ionic source code, core->src->components->modal->test->basic and add to test ion-slides, first time when modal is opened everything is ok, second time that modal is opened it is unresponsive, if you change ion-button in test with anchor tag everything is going to be ok

Related code:

Not working

 async function createModal() {
    // initialize controller
    const modalController = document.querySelector('ion-modal-controller');
    await modalController.componentOnReady();

    // create component to open
    const element = document.createElement('div');
    element.innerHTML = `
      <ion-header>
        <ion-toolbar>
          <ion-title>Super Modal</ion-title>
        </ion-toolbar>
      </ion-header>
      <ion-content>
        <h1>Content of doom</h1>
        <div>Here's some more content</div>
        <ion-slides mode="md">
          <ion-slide>
            <div>1</div>
          </ion-slide>
          <ion-slide>
            <div>2</div>
          </ion-slide>
          <ion-slide>
            <div>3</div>
          </ion-slide>
        </ion-slides>
      <ion-button class="dismiss">Dismiss Modal</ion-button>
    </ion-content>
      `;

    // listen for close event
    const button = element.querySelector('ion-button');
    button.addEventListener('click', () => {
      modalController.dismiss();
    });

    // present the modal
    const modalElement = await modalController.create({
      component: element
    });
    return modalElement;
  }

Working

  async function createModal() {
    // initialize controller
    const modalController = document.querySelector('ion-modal-controller');
    await modalController.componentOnReady();

    // create component to open
    const element = document.createElement('div');
    element.innerHTML = `
      <ion-header>
        <ion-toolbar>
          <ion-title>Super Modal</ion-title>
        </ion-toolbar>
      </ion-header>
      <ion-content>
        <h1>Content of doom</h1>
        <div>Here's some more content</div>
        <ion-slides mode="md">
          <ion-slide>
            <div>1</div>
          </ion-slide>
          <ion-slide>
            <div>2</div>
          </ion-slide>
          <ion-slide>
            <div>3</div>
          </ion-slide>
        </ion-slides>
      <a class="dismiss">Dismiss Modal</a>
    </ion-content>
      `;

    // listen for close event
    const button = element.querySelector('a');
    button.addEventListener('click', () => {
      modalController.dismiss();
    });

    // present the modal
    const modalElement = await modalController.create({
      component: element
    });
    return modalElement;
  }

Other information:

Ionic info:

insert the output from ionic info here

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:9
  • Comments:16 (2 by maintainers)

github_iconTop GitHub Comments

21reactions
zankevichcommented, Jan 17, 2020

Better solution, use Ionic lifecycle hook:

ionViewDidEnter() {
    this.showSlides = true;
}

It’s more clear what the code is trying to accomplish rather than arbitrary timeouts.

In my case that was a fix:

import { IonSlides } from '@ionic/angular';

@ViewChild(IonSlides, { static: true }) slides: IonSlides;

ngOnInit() {
  this.slides.update();
}
20reactions
pipoacommented, Feb 23, 2019

same here, showing IonSlides in a modal page result in a serious DEAD LOCK, chrome stops responding. no matter <ion-button> or <button>, the issue persistent. temperory solution is adding a settimeout to delay show IonSlides

<div *ngIf="showSlides" class="slides-container">
    <ion-slides>
      <ion-slide *ngFor="let photo of photos">
        <img data-src="{{photo.url}}" class="slide-image"/>
        <div class="title" *ngIf="photo.title">{{photo.title}}</div>
      </ion-slide>
    </ion-slides>
</div>

ngOnInit() { setTimeout(() => { this.showSlides = true; }, 0); }

@ionic/angular 4.0.2

Read more comments on GitHub >

github_iconTop Results From Across the Web

IonSlides ref not working when inside IonModal - Ionic Vue
I want to use the “slideTo” method with IonSlides in Ionic Vue. I tried adding a ref attribute like this: <ion-modal ...
Read more >
ionic 4/5 issue with ion-slide and modal - Stack Overflow
I am trying to show an image preview using ion-slide inside the ion-modal. But zoom functionality is not working. I have added slideOptions....
Read more >
How to Navigate in Ionic Modals with ion-nav - Ionic Blog
Let's build an app with navigation inside of a modal and make everything work, including the Android back button as well! Getting Started...
Read more >
Ionic4 模态框组件ion-modal
A Modal is a dialog that appears on top of the app's content, and must be dismissed by the app before interaction can...
Read more >
Building the Netflix UI with Ionic | Devdactic
We will work with directives to fade the header out, create a semi transparent modal with blurred background and also a bottom drawer...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found