From f74ce3f2f5f4bf1eaf61730e38b8b914941f2a42 Mon Sep 17 00:00:00 2001 From: Vlad Date: Sun, 12 Sep 2021 15:31:25 +0300 Subject: [PATCH 1/2] feat(angular): `enabled` prop --- playground/angular/src/app/home/home.component.html | 10 ++++++++++ playground/angular/src/app/home/home.component.ts | 5 +++++ src/angular/src/swiper.component.ts | 11 ++++++++++- src/angular/src/utils/params-list.ts | 1 + 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/playground/angular/src/app/home/home.component.html b/playground/angular/src/app/home/home.component.html index 26e2e5aff..e37ca10af 100644 --- a/playground/angular/src/app/home/home.component.html +++ b/playground/angular/src/app/home/home.component.html @@ -1,4 +1,14 @@
+
+

Enable / disable

+ + test vertical 2 + test vertical 2 + test vertical 2 + test vertical 2 + + +

Slide change

diff --git a/playground/angular/src/app/home/home.component.ts b/playground/angular/src/app/home/home.component.ts index 12d606e3d..a2712bde4 100644 --- a/playground/angular/src/app/home/home.component.ts +++ b/playground/angular/src/app/home/home.component.ts @@ -43,6 +43,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: Swiper; setThumbsSwiper(swiper: Swiper) { this.thumbsSwiper = swiper; diff --git a/src/angular/src/swiper.component.ts b/src/angular/src/swiper.component.ts index 801cfc927..150926637 100644 --- a/src/angular/src/swiper.component.ts +++ b/src/angular/src/swiper.component.ts @@ -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']; @@ -732,6 +733,7 @@ export class SwiperComponent implements OnInit { continue; } const newValue = changedParams[key]?.currentValue ?? changedParams[key]; + console.log(newValue, key); this.updateParameter(key, newValue); } @@ -807,7 +809,14 @@ export class SwiperComponent implements OnInit { this.swiperRef.params[_key] = defaultParams; } } - + if (_key === 'enabled') { + if (value === true) { + this.swiperRef.enable(); + } else { + this.swiperRef.disable(); + } + return; + } if (isCurrentParamObj && isObject(value)) { extend(this.swiperRef.params[_key], value); } else { diff --git a/src/angular/src/utils/params-list.ts b/src/angular/src/utils/params-list.ts index 222f27181..bc534523c 100644 --- a/src/angular/src/utils/params-list.ts +++ b/src/angular/src/utils/params-list.ts @@ -1,6 +1,7 @@ /* underscore in name -> watch for changes */ export const paramsList = [ 'init', + 'enabled', '_direction', 'touchEventsTarget', 'initialSlide', From eb18d769b2f2c2bfd5b2df0ad9f2bc9c051c7eb9 Mon Sep 17 00:00:00 2001 From: Vlad Date: Mon, 13 Sep 2021 10:02:02 +0300 Subject: [PATCH 2/2] fix(angular): enabled prop --- src/angular/src/swiper.component.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/angular/src/swiper.component.ts b/src/angular/src/swiper.component.ts index 150926637..e81ba2624 100644 --- a/src/angular/src/swiper.component.ts +++ b/src/angular/src/swiper.component.ts @@ -733,7 +733,6 @@ export class SwiperComponent implements OnInit { continue; } const newValue = changedParams[key]?.currentValue ?? changedParams[key]; - console.log(newValue, key); this.updateParameter(key, newValue); } @@ -812,7 +811,7 @@ export class SwiperComponent implements OnInit { if (_key === 'enabled') { if (value === true) { this.swiperRef.enable(); - } else { + } else if (value === false) { this.swiperRef.disable(); } return;