From c96bcf65a818d56a4ed949b43078bc5a5e4980ad Mon Sep 17 00:00:00 2001 From: Vlad Date: Tue, 27 Apr 2021 08:23:50 +0300 Subject: [PATCH] fix(angular): custom naviation & pagination --- src/angular/src/swiper.component.ts | 31 +++++++++++------------------ src/angular/src/utils/utils.ts | 10 ++++++++++ 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/src/angular/src/swiper.component.ts b/src/angular/src/swiper.component.ts index fe909d7e6..3b94fd560 100644 --- a/src/angular/src/swiper.component.ts +++ b/src/angular/src/swiper.component.ts @@ -27,6 +27,7 @@ import { setProperty, ignoreNgOnChanges, coerceBooleanProperty, + isShowEl, } from './utils/utils'; import { SwiperOptions, @@ -169,13 +170,15 @@ export class SwiperComponent implements OnInit { prevEl: currentPrev || null, }); if ( - coerceBooleanProperty(val) !== true && - typeof this._navigation !== 'boolean' && - this._navigation?.prevEl !== this._prevElRef?.nativeElement && - (typeof this._navigation?.nextEl === 'string' || - typeof this._navigation?.prevEl === 'string' || - typeof this._navigation?.nextEl === 'object' || - typeof this._navigation?.prevEl === 'object') + coerceBooleanProperty(val) !== true || + (this._navigation && + typeof this._navigation !== 'boolean' && + this._navigation.prevEl !== this._prevElRef?.nativeElement && + (this._navigation.prevEl !== null || this._navigation.nextEl !== null) && + (typeof this._navigation.nextEl === 'string' || + typeof this._navigation.prevEl === 'string' || + typeof this._navigation.nextEl === 'object' || + typeof this._navigation.prevEl === 'object')) ) { this.showNavigation = false; } @@ -192,12 +195,7 @@ export class SwiperComponent implements OnInit { this._pagination = setProperty(val, { el: current || null, }); - if ( - coerceBooleanProperty(val) !== true && - typeof this._pagination !== 'boolean' && - this._pagination?.el !== this._paginationElRef?.nativeElement && - (typeof this._pagination?.el === 'string' || typeof this._pagination?.el === 'object') - ) { + if (isShowEl(val, this._pagination, this._paginationElRef)) { this.showPagination = false; } } @@ -213,12 +211,7 @@ export class SwiperComponent implements OnInit { this._scrollbar = setProperty(val, { el: current || null, }); - if ( - coerceBooleanProperty(val) !== true && - typeof this._scrollbar !== 'boolean' && - this._scrollbar?.el !== this._scrollbarElRef?.nativeElement && - (typeof this._scrollbar?.el === 'string' || typeof this._scrollbar?.el === 'object') - ) { + if (isShowEl(val, this._scrollbar, this._scrollbarElRef)) { this.showScrollbar = false; } } diff --git a/src/angular/src/utils/utils.ts b/src/angular/src/utils/utils.ts index 451fc5625..488addbef 100644 --- a/src/angular/src/utils/utils.ts +++ b/src/angular/src/utils/utils.ts @@ -7,6 +7,16 @@ export function isObject(o) { ); } +export function isShowEl(val, obj, el) { + return ( + coerceBooleanProperty(val) !== true || + (obj && + typeof obj !== 'boolean' && + obj.el !== el?.nativeElement && + (typeof obj.el !== 'string' || typeof obj.el !== 'object')) + ); +} + export function extend(target, src) { const noExtend = ['__proto__', 'constructor', 'prototype']; Object.keys(src)