[英]Ionic 4 ion-slides slideOptions ignore the second time
I have a strange behavior with my Ionic 4 App : When I open a modal with slides for the second time my slideOptions are ignored (it work perfectly the first time)我的 Ionic 4 应用程序有一个奇怪的行为:当我第二次打开带有幻灯片的模式时,我的 slideOptions 被忽略(它第一次完美运行)
Here is some code这是一些代码
my-card.component.ts : my-card.component.ts :
async openDetail(): Promise<void> {
const detailModal = await this.modalController.create({
component: DetailsComponent,
componentProps: {
somePros: '...'
}
});
return detailModal.present();
}
details.component.ts :细节.component.ts:
export class DetailsComponent implements OnInit {
slideOptions = null;
ngOnInit() {
// [...]
let initialSlide = 0;
// [...]
this.slideOptions = { initialSlide };
}
...
}
details.component.html : details.component.html :
<ion-content>
[...]
<ion-slides *ngIf="slideOptions" [options]="slideOptions">
<ion-slide>
[...]
</ion-slide>
[...]
</ion-slides>
</ion-content>
Apparently I needed to update the slides for it to work显然我需要更新幻灯片才能让它工作
details.component.ts :细节.component.ts:
export class DetailsComponent implements OnInit {
slideOptions = null;
// ===> Get the reference on the slides here <===
@ViewChild('slides', {static: true}) slides: IonSlides;
ngOnInit() {
// [...]
let initialSlide = 0;
// [...]
this.slideOptions = { initialSlide };
// ===> Update the slides here <===
this.slides.update();
}
...
}
details.component.html : details.component.html :
<ion-content>
[...]
<!-- ===> Add #slides here <=== -->
<ion-slides #slides *ngIf="slideOptions" [options]="slideOptions">
<ion-slide>
[...]
</ion-slide>
[...]
</ion-slides>
</ion-content>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.