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.

bug: ion-slides swiper instance does not get re-initialized with angular ivy

See original GitHub issue

Bug Report

Ionic version:

[x] 5.0.0-rc.2

Current behavior: With angular ivy enabled (9.0.0-rc.12) ion-slides (specifically the swiper instance) does not get re-initialized after destroyed once and is therefore unusable afterwards.

Expected behavior: Swiper instance gets re-initialized, ion-slides keep working.

Steps to reproduce:

  • clone sample app
  • npm i
  • ionic serve
  • open console
  • click on “Go to slides page”
  • click “Go to next slide” (working!)
  • click back button
  • click on “Go to slides page” again
  • “Go to next slide”, “Go to previous slide” is broken
  • check console, unfold logged Swiper object -> destroyed: true

Related code:

A sample application via GitHub

Other information: Removing the following line fixes the problem, but I don’t think that its a solution to the problem.

https://github.com/ionic-team/ionic/blob/ae4e28969f1d7b3e41f16f4f70c6befdaca6118f/core/src/components/slides/slides.tsx#L153

Related: ngx-swiper-wrapper#226 As ionic is shipping the swiper directly embedded into the framework maybe it needs to be compiled with ngcc once.

Ionic info:

Ionic:

   Ionic CLI                     : 5.4.15 (/usr/local/lib/node_modules/ionic)
   Ionic Framework               : @ionic/angular 5.0.0-rc.2
   @angular-devkit/build-angular : 0.900.0-rc.12
   @angular-devkit/schematics    : 9.0.0-rc.12
   @angular/cli                  : 9.0.0-rc.12
   @ionic/angular-toolkit        : 2.1.2

Cordova:

   Cordova CLI       : 9.0.0 (cordova-lib@9.0.1)
   Cordova Platforms : ios 5.1.1
   Cordova Plugins   : cordova-plugin-ionic-keyboard 2.2.0, cordova-plugin-ionic-webview 4.1.3, (and 4 other plugins)

Utility:

   cordova-res : not installed
   native-run  : not installed

System:

   ios-deploy : 1.9.2
   ios-sim    : 8.0.2
   NodeJS     : v12.4.0 (/usr/local/bin/node)
   npm        : 6.11.3
   OS         : macOS Catalina
   Xcode      : Xcode 11.3.1 Build version 11C504

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:18
  • Comments:38 (18 by maintainers)

github_iconTop GitHub Comments

16reactions
DavidWiesnercommented, Feb 26, 2020

Here is a workaround for this issue. Simply postpone the slider initialization with ngIf and the angular lifecycle.

my-component.html

<ion-slides *ngIf="didInit">
   <!-- multiple <ion-slide/> -->
</ion-slides>

my-component.ts

@Component({
    templateUrl: 'my-component.html'
})
export class MyComponent implements AfterViewInit {
    public didInit: boolean = false;

    ngAfterViewInit() {
        this.didInit = true;
    }
}
5reactions
liamdebeasicommented, Mar 31, 2020

Thanks for the issue. This has been resolved via https://github.com/ionic-team/ionic/pull/20899 and will be available in an upcoming release of Ionic Framework.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Ionic 5 angular - migrate ion-slides to swiper.js
Error: Type SwiperComponent is part of the declarations of 2 modules. The issue above basically occurs when a component is declared in 2 ......
Read more >
Set Up Swiper.js for Angular Slides [Example]
Read this guide to learn how to get Swiper.js for Angular set up in your Ionic Framework application for a modern touch slider...
Read more >
swiper js get current slide
Current behavior: With angular ivy enabled (9.0.0-rc.12) ion-slides (specifically the swiper instance) does not get re-initialized after destroyed once and ...
Read more >
How to use Swiper with Ionic (instead of ion-slides) - YouTube
In this video we will implement the Swiper component without ion-slides, since it will be deprecated with Framework v6!
Read more >
Building a slideshow with Ionic Slides API
Out of all of these my favourite has to the Ion Slides component ... into the underlying Swiper API that the Ionic Slides...
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