Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(angular): enabled prop #4949

Merged
merged 3 commits into from
Sep 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions playground/angular/src/app/home/home.component.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
<main>
<div>
<h4>Enable / disable</h4>
<swiper [enabled]="enabled" [pagination]="true">
<ng-template swiperSlide> test vertical 2 </ng-template>
<ng-template swiperSlide> test vertical 2 </ng-template>
<ng-template swiperSlide> test vertical 2 </ng-template>
<ng-template swiperSlide> test vertical 2 </ng-template>
</swiper>
<button (click)="toggleEnabled()">{{ enabled ? 'Disable' : 'Enable' }}</button>
</div>
<div>
<h4>data-swiper-autoplay</h4>
<swiper
Expand Down
5 changes: 5 additions & 0 deletions playground/angular/src/app/home/home.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ export class HomePage {
this.slides$.next(Array.from({ length: 600 }).map((el, index) => `Slide ${index + 1}`));
}

enabled: boolean = false;
toggleEnabled() {
this.enabled = !this.enabled;
}

thumbsSwiper: SwiperCore;
setThumbsSwiper(swiper: SwiperCore) {
this.thumbsSwiper = swiper;
Expand Down
10 changes: 9 additions & 1 deletion src/angular/src/swiper.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import { isPlatformBrowser } from '@angular/common';
],
})
export class SwiperComponent implements OnInit {
@Input() enabled: SwiperOptions['enabled'];
@Input() direction: SwiperOptions['direction'];
@Input() touchEventsTarget: SwiperOptions['touchEventsTarget'];
@Input() initialSlide: SwiperOptions['initialSlide'];
Expand Down Expand Up @@ -807,7 +808,14 @@ export class SwiperComponent implements OnInit {
this.swiperRef.params[_key] = defaultParams;
}
}

if (_key === 'enabled') {
if (value === true) {
this.swiperRef.enable();
} else if (value === false) {
this.swiperRef.disable();
}
return;
}
if (isCurrentParamObj && isObject(value)) {
extend(this.swiperRef.params[_key], value);
} else {
Expand Down
1 change: 1 addition & 0 deletions src/angular/src/utils/params-list.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* underscore in name -> watch for changes */
export const paramsList = [
'init',
'enabled',
'_direction',
'touchEventsTarget',
'initialSlide',
Expand Down