angular2-useful-swiper
angular2-useful-swiper copied to clipboard
swiper doesn't work on ngIf variable change
Hi,
I'm using angular2-useful-swiper on Angular 9 but I have a problem.
If I use angular2-useful-swiperwith ngIf it doesn't work correctly.
<div *ngIf="myVariable"><swiper....></swiper></div>
on init my variable is equal to TRUE.
onAfterViewInit I subscribe a BehaviourSubject that is changed from false to true and myVariable is updated to true.
Then the Div show the swiper but the slides doesn't move on click dots or arrows BUT autoplay works.
Can someone help me?
Can you try passing [intialized]
variable to swiper component?
<swiper [initialized]="myVariable">
<ng-container *ngIf="myVariable">
<!-- ngFor items -->
</ng-container>
</swiper>
In the implementation of this repo, it control swiper through shouldInitialized
variable which is updated from [initialized]
Input. Also, they update swiper when swiper's childElementCount is different with slideCount (it means ngFor loop create/delete some DOM element)
ngAfterViewChecked() {
if (this.shouldInitialize) {
this.setup();
}
if (
this.swiperWrapper &&
this.slideCount !== this.swiperWrapper.childElementCount
) {
this.slideCount = this.swiperWrapper.childElementCount;
this.swiper.update();
}
}
I am facing the same issue. Any update on this?