Hi, I have a very frustrating problem with IonSlider.
I have always called getActiveIndex() from within the ionSlideWiilChange
handler (I swapped to ionSlideDidChange
to see if this made any difference, and it didn’t
@ViewChild('slider', { static: true }) private slider: IonSlides;
....
public async ionSlideDidChange(): Promise<void> {
try {
this.logger.debug(`getting active index...`);
this.currentSliderIndex = await this.slider.getActiveIndex();
if (!this.currentSliderIndex)
this.currentSliderIndex = 0;
this.logger.info(`index set to ${this.currentSliderIndex}`);
await this.dataStore.setNumber(DataStorageKeys.vals.lastActiveSlideIndex, this.currentSliderIndex);
this.subscribeToUpdates();
} catch (error) {
this.logger.error(`ionSlideWillChange: ${error}`);
}
}
This has always worked for me in Ionic 4 - I have never had any problems with it.
I have just upgraded to Ionic 5
. The first time I go into this feature page, the above still works.
But if I navigate away (to another page), and then back, the next time I “slide” ionSlideDidChange
is still called, but the call to this.slider.getActiveIndex()
never returns.
I have also tried using tradition promise syntax…
this.slider.getActiveIndex().then (index => {
..
}
But exactly the same problem, the then
is never called.
I Have tried to step into getActiveIndex()
, but it goes into code I just don’t understand.
I am getting no exceptions or console errors.
If I do the same thing in a small sample app, i do NOT get the same problem, so I cannot even use this to report it.
I am stuck, I have no idea how I am going track down this problem.
Does anyone have any advice, or had anything similar?
Thanks in advance for any help.
$ ionic info
Ionic:
Ionic CLI : 5.2.3 (C:\Users\pchapman\AppData\Roaming\npm\node_modules\ionic)
Ionic Framework : @ionic/angular 5.0.7
@angular-devkit/build-angular : 0.901.0
@angular-devkit/schematics : 9.1.0
@angular/cli : 9.1.0
@ionic/angular-toolkit : 2.2.0
Cordova:
Cordova CLI : 9.0.0 (cordova-lib@9.0.1)
Cordova Platforms : android 8.1.0, windows 7.0.1
Cordova Plugins : cordova-plugin-ionic-keyboard 2.1.3, cordova-plugin-ionic-webview 4.1.3, (and 14 other plugins)
Utility:
cordova-res : 0.7.0-testing.0
native-run : 0.2.8
System:
Android SDK Tools : 26.1.1 (C:\Users\pchapman\AppData\Local\Android\sdk)
NodeJS : v10.15.3 (C:\Program Files\nodejs\node.exe)
npm : 6.4.1
OS : Windows 10