I create Slides
based on a condition. When the condition is true the Slides
component is initialized.
<ion-slides *ngIf="condition === true">
<ion-slide *ngFor="let question of questions">
// slide content
</ion-slide>
</ion-slides>
Addionally I disable swipe by setting onlyExternal = true
. Since this is not an input property I have to set the value in the parent component's ngAfterViewInit
method.
import { Component, ViewChild, AfterViewInit } from '@angular/core';
import { Slides } from 'ionic-angular';
@Component{
...
}
export class QuizPage implements AfterViewInit {
@ViewChild(Slides) slides: Slides;
...
ngAfterViewInit {
this.slides.onlyExternal = true;
}
...
}
When the view condition changes the Slides
-component gets destroyed and looses the onlyExternal
setting. It gets initialized again when the condition is fulfilled, but ngAfterViewInit
is only called once, when the parent component is initialized. Which means the onlyExternal
setting is not set.
Currently I use ngAfterViewChecked
, but it gets called quite often, I was wondering if there is a better way to solve this problem.
ngAfterViewChecked() {
if(this.slides) {
this.slides.onlyExternal = true;
}
}