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

Commit

Permalink
Fixed disabled control to work with latest Swiper
Browse files Browse the repository at this point in the history
  • Loading branch information
sconix committed Jan 24, 2018
1 parent 9116ce2 commit 97dd713
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
4 changes: 2 additions & 2 deletions example/src/app/app.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@
<div class="box-title">Swiper</div>

<div class="content-container" fxLayout="column" fxLayoutAlign="stretch" fxFlex="auto">
<swiper *ngIf="type == 'component' && show" class="swiper-container" [config]="config" (indexChange)="onIndexChange($event)" fxFlex="auto">
<swiper *ngIf="type == 'component' && show" class="swiper-container" [config]="config" [disabled]="disabled" (indexChange)="onIndexChange($event)" fxFlex="auto">
<div *ngFor="let slide of slides" class="swiper-slide">
<div fxLayout="column" fxLayoutAlign="center center" fxFlexFill>
{{slide}}
</div>
</div>
</swiper>

<div *ngIf="type == 'directive' && show" class="swiper-container" [swiper]="config" (indexChange)="onIndexChange($event)">
<div *ngIf="type == 'directive' && show" class="swiper-container" [disabled]="disabled" [swiper]="config" (indexChange)="onIndexChange($event)">
<div class="swiper-wrapper">
<div *ngFor="let slide of slides" class="swiper-slide">
<div fxLayout="column" fxLayoutAlign="center center" fxFlexFill>
Expand Down
13 changes: 11 additions & 2 deletions src/lib/swiper.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ export class SwiperDirective implements OnInit, DoCheck, OnDestroy, OnChanges {
};
}

if (this.disabled) {
params.allowSlidePrev = false;
params.allowSlideNext = false;
}

if (this.initialIndex != null) {
params.initialSlide = this.initialIndex;

Expand Down Expand Up @@ -189,11 +194,15 @@ export class SwiperDirective implements OnInit, DoCheck, OnDestroy, OnChanges {
if (changes['disabled'].currentValue !== changes['disabled'].previousValue) {
if (changes['disabled'].currentValue === true) {
this.zone.runOutsideAngular(() => {
this.instance.lockSwipes();
this.ngOnDestroy();

this.ngOnInit();
});
} else if (changes['disabled'].currentValue === false) {
this.zone.runOutsideAngular(() => {
this.instance.unlockSwipes();
this.ngOnDestroy();

this.ngOnInit();
});
}
}
Expand Down

0 comments on commit 97dd713

Please sign in to comment.