Skip to content
This repository has been archived by the owner on Aug 6, 2022. It is now read-only.

Commit

Permalink
Fix slide class adding for static slides, fixes #60
Browse files Browse the repository at this point in the history
  • Loading branch information
sconix committed Sep 28, 2017
1 parent c9ed01b commit bf0a08c
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions src/lib/swiper.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,10 @@ export class SwiperComponent implements OnInit, OnDestroy {

ngOnInit() {
this.zone.runOutsideAngular(() => {
this.mo = new MutationObserver((mutations) => {
const children = this.swiperSlides.nativeElement.children;

for (let i = 0; i < children.length; i++) {
children[i].classList.add('swiper-slide');
}
this.updateClasses();

this.directiveRef.update();
this.mo = new MutationObserver((mutations) => {
this.updateClasses();
});

this.mo.observe(this.swiperSlides.nativeElement, { childList: true });
Expand Down Expand Up @@ -163,6 +159,24 @@ export class SwiperComponent implements OnInit, OnDestroy {
return options;
}

updateClasses() {
let updateNeeded = false;

const children = this.swiperSlides.nativeElement.children;

for (let i = 0; i < children.length; i++) {
if (!children[i].classList.contains('swiper-slide')) {
updateNeeded = true;

children[i].classList.add('swiper-slide');
}
}

if (updateNeeded) {
this.directiveRef.update();
}
}

update(updateTranslate?: boolean) {
console.warn('Deprecated function, update needs to be called through directiveRef!');

Expand Down

0 comments on commit bf0a08c

Please sign in to comment.