Skip to content

Commit

Permalink
fix(angular): BrowserAnimationsModule slides deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
vltansky committed Feb 4, 2021
1 parent 955543e commit fef6ebd
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 3 deletions.
15 changes: 15 additions & 0 deletions playground/angular/src/app/app.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,19 @@

<button (click)="show = !show">Toggle show</button>
{{ exampleConfig | json }}
<swiper
#swiper
[slidesPerView]="1"
[centeredSlides]="true"
[navigation]="{ prevEl: '.swiper-navigation-prev', nextEl: '.swiper-navigation-next' }"
[pagination]="{ type: 'fraction' }"
>
<ng-template swiperSlide *ngFor="let slide of slides2; index as i">
{{ i }} - {{ slide }}
</ng-template>
</swiper>
<button type="button" class="swiper-navigation-prev">&lt;</button>
<button type="button" class="swiper-navigation-next">&gt;</button>
<hr />
<button (click)="replaceSlides()">replace slides</button>
</main>
5 changes: 5 additions & 0 deletions playground/angular/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ export class AppComponent {
slidesPerView: number = 4;
pagination: any = false;

slides2 = ['slide 1', 'slide 2', 'slide 3'];
replaceSlides() {
this.slides2 = ['foo', 'bar'];
}

togglePagination() {
if (!this.pagination) {
this.pagination = { clickable: true };
Expand Down
7 changes: 6 additions & 1 deletion playground/angular/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@ import { NgModule } from '@angular/core';

import { AppComponent } from './app.component';
import { SwiperModule } from 'src/angular/src/public-api';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';

@NgModule({
declarations: [AppComponent],
imports: [BrowserModule.withServerTransition({ appId: 'serverApp' }), SwiperModule],
imports: [
BrowserModule.withServerTransition({ appId: 'serverApp' }),
SwiperModule,
BrowserAnimationsModule,
],
providers: [],
bootstrap: [AppComponent],
})
Expand Down
10 changes: 8 additions & 2 deletions src/angular/src/swiper.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -465,8 +465,14 @@ export class SwiperComponent implements OnInit {
this.prependSlides = of(this.slides.slice(this.slides.length - this.loopedSlides));
this.appendSlides = of(this.slides.slice(0, this.loopedSlides));
}
this._changeDetectorRef.detectChanges();
this.swiperRef?.update();
this._changeDetectorRef.markForCheck();
if (this.swiperRef) {
this.zone.runOutsideAngular(() => {
setTimeout(() => {
this.swiperRef.update();
});
});
}
};

get isSwiperActive() {
Expand Down

0 comments on commit fef6ebd

Please sign in to comment.