From 9303eaf8e329d41a8b9411b47fd020ae648cf508 Mon Sep 17 00:00:00 2001 From: Robert Isaac Date: Wed, 16 Oct 2019 17:34:51 +0200 Subject: [PATCH] add safe check to OCarouselContainerComponent to prevent throwing errors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fix: when an event trigger on OCarouselContainerComponent before swiper being initialized, it throw errors   this commit tries to prevent that by add safe checks to make sure that swiper is defined before it tries to stop/start the autoplay fix https://github.com/Orange-OpenSource/Orange-Boosted-Angular/issues/120 --- .../o-carousel-container.component.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/projects/ng-boosted/src/lib/o-carousel/o-carousel-container/o-carousel-container.component.ts b/projects/ng-boosted/src/lib/o-carousel/o-carousel-container/o-carousel-container.component.ts index c45f0769..be896420 100644 --- a/projects/ng-boosted/src/lib/o-carousel/o-carousel-container/o-carousel-container.component.ts +++ b/projects/ng-boosted/src/lib/o-carousel/o-carousel-container/o-carousel-container.component.ts @@ -82,22 +82,30 @@ import { }); } @HostListener('mouseenter') public onMouseEnter() { - this.swiper.autoplay.stop(); + if (this.swiper) { + this.swiper.autoplay.stop(); + } this.pause = !this.pause; } @HostListener('mouseleave') public onMouseLeave() { - this.swiper.autoplay.start(); + if (this.swiper) { + this.swiper.autoplay.start(); + } this.pause = !this.pause; } @HostListener('focus') public onFocusIn() { - this.swiper.autoplay.start(); + if (this.swiper) { + this.swiper.autoplay.start(); + } this.pause = !this.pause; } @HostListener('blur') public onFocusOut() { - this.swiper.autoplay.start(); + if (this.swiper) { + this.swiper.autoplay.start(); + } this.pause = !this.pause; } }