From e33242ce41149265f04224380981c34386ec72b4 Mon Sep 17 00:00:00 2001 From: Vlad Date: Wed, 24 Mar 2021 10:42:27 +0200 Subject: [PATCH] fix: update virtual slides --- playground/angular/src/app/app.component.html | 148 ++++++++++-------- playground/angular/src/app/app.component.ts | 6 + src/angular/src/swiper.component.ts | 5 + 3 files changed, 93 insertions(+), 66 deletions(-) diff --git a/playground/angular/src/app/app.component.html b/playground/angular/src/app/app.component.html index a09ec7389..d7a7294c5 100644 --- a/playground/angular/src/app/app.component.html +++ b/playground/angular/src/app/app.component.html @@ -5,7 +5,7 @@ [slidesPerView]="3" [spaceBetween]="50" [pagination]="{ type: 'fraction' }" - virtual + [virtual]="true" slideActiveClass="swiper-active whyWouldIuseCustomClass" [centeredSlides]="true" navigation @@ -16,6 +16,22 @@ Slide Slide + + + Slide {{ slide }} + + + @@ -91,69 +107,69 @@
- - Slide 1 - Slide 2 - Slide 3 - Slide 4 - Slide 5 - Slide 6 - - - Slide 1 - Slide 2 - Slide 3 - Slide 4 - Slide 5 - Slide 6 - -
-
- - Slide 1 - Slide 2 - Slide 3 - Slide 4 - Slide 5 - Slide 6 - - - Slide 1 - Slide 2 - Slide 3 - Slide 4 - Slide 5 - Slide 6 - -
+ + Slide 1 + Slide 2 + Slide 3 + Slide 4 + Slide 5 + Slide 6 + + + Slide 1 + Slide 2 + Slide 3 + Slide 4 + Slide 5 + Slide 6 + + +
+ + Slide 1 + Slide 2 + Slide 3 + Slide 4 + Slide 5 + Slide 6 + + + Slide 1 + Slide 2 + Slide 3 + Slide 4 + Slide 5 + Slide 6 + +
diff --git a/playground/angular/src/app/app.component.ts b/playground/angular/src/app/app.component.ts index 749f33cea..43e473bda 100644 --- a/playground/angular/src/app/app.component.ts +++ b/playground/angular/src/app/app.component.ts @@ -1,4 +1,5 @@ import { ChangeDetectorRef, Component, ViewChild } from '@angular/core'; +import { BehaviorSubject } from 'rxjs'; import { SwiperComponent } from 'src/angular/src/public-api'; import SwiperCore, { Navigation, @@ -34,9 +35,14 @@ export class AppComponent { show: boolean; thumbs: any; + slides$ = new BehaviorSubject(['']); constructor(private cd: ChangeDetectorRef) {} ngOnInit() {} + getSlides() { + this.slides$.next(Array.from({ length: 600 }).map((el, index) => `Slide ${index + 1}`)); + } + thumbsSwiper: any; setThumbsSwiper(swiper) { this.thumbsSwiper = swiper; diff --git a/src/angular/src/swiper.component.ts b/src/angular/src/swiper.component.ts index 1c666883e..adec92a9e 100644 --- a/src/angular/src/swiper.component.ts +++ b/src/angular/src/swiper.component.ts @@ -471,6 +471,11 @@ export class SwiperComponent implements OnInit { if (!this.virtual) { this.prependSlides = of(this.slides.slice(this.slides.length - this.loopedSlides)); this.appendSlides = of(this.slides.slice(0, this.loopedSlides)); + } else if (this.swiperRef && this.swiperRef.virtual) { + this._ngZone.runOutsideAngular(() => { + this.swiperRef.virtual.slides = this.slides; + this.swiperRef.virtual.update(true); + }); } this._changeDetectorRef.detectChanges(); };