pratik jaiswal
pratik jaiswal

Reputation: 2065

ionic 4/5 issue with ion-slide and modal

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. But not working. Subsequently, the zoom functionality is working with the normal page.

Second issue backdropDismiss : true not closing modal when the backdrop is clicked

here is the code

page.html

<ion-slides [options]="slideOpts">
    <ion-slide *ngFor="let p of products">
          <img [src] = 'p.image_url' tappable (click)="openPreview(p.image_url)">

     </ion-slide>
 </ion-slides>

page.ts

async openPreview(image_url){
    console.log(image_url)

    const modal = await this.modalController.create({
      component: ImageModalPage,
      showBackdrop:true,
      backdropDismiss: true,
      componentProps: {
        image_url : image_url,
      },
    });
    return await modal.present();

  }

modal.html

<ion-item class="close-fake" lines="none" text-center>
    <ion-button (click)="close()" fill="clear" color="light">
      <ion-icon name="close" slot="start"></ion-icon>
      back
    </ion-button>

    <ion-slides [options]="sliderOpts">
        <ion-slide>
          <div class="swiper-zoom-container">
            <img [src] ='image_url'>
          </div>
        </ion-slide>
      </ion-slides>

modal.ts

    sliderOpts = {
        zoom: {
          maxRatio: 5,
        }
      }

close(){
    this.modalController.dismiss()
  }

Upvotes: 4

Views: 1892

Answers (2)

tobika
tobika

Reputation: 1327

Had similar problem and solved it by adding the slider later to the DOM via an *ngIf

Solution from here: https://github.com/ionic-team/ionic-framework/issues/17522#issuecomment-466631844

Upvotes: 1

Aram Avetisyan
Aram Avetisyan

Reputation: 61

In html set event (ionSlidesDidLoad)="ionViewDidEnter" and #slides for get in code

 @ViewChild("slides") slides!: any;
 ionViewDidEnter(){
    this.slides.update();
  }

Upvotes: 6

Related Questions