From 8d6522270c26451c7474630fc71e7fa3e31c5c0e Mon Sep 17 00:00:00 2001 From: "k.triantafyllou" Date: Mon, 16 Oct 2023 14:34:48 +0300 Subject: [PATCH] Slider container: Fix error about observer --- .../slider-container.component.ts | 40 ++++++++++--------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/sharedComponents/slider-utils/slider-container.component.ts b/sharedComponents/slider-utils/slider-container.component.ts index 1fd18467..4eea093d 100644 --- a/sharedComponents/slider-utils/slider-container.component.ts +++ b/sharedComponents/slider-utils/slider-container.component.ts @@ -60,7 +60,7 @@ export class SliderContainerComponent implements OnInit, OnDestroy, AfterContent } ngOnDestroy() { - if(this.observer) { + if(this.observer && typeof IntersectionObserver !== 'undefined') { this.observer.disconnect(); } } @@ -78,24 +78,26 @@ export class SliderContainerComponent implements OnInit, OnDestroy, AfterContent } setObserver() { - let options = { - root: null, - rootMargin: '0px', - threshold: 0.1 - }; - this.observer = new IntersectionObserver(entries => { - entries.forEach(entry => { - if (entry.isIntersecting && !this.initialized) { - this.stopped = false; - this.start(0); - this.initialized = true; - } else { - this.initialized = false; - this.stopped = true; - } - }); - }, options); - this.observer.observe(this.element.nativeElement); + if(typeof IntersectionObserver !== 'undefined') { + let options = { + root: null, + rootMargin: '0px', + threshold: 0.1 + }; + this.observer = new IntersectionObserver(entries => { + entries.forEach(entry => { + if (entry.isIntersecting && !this.initialized) { + this.stopped = false; + this.start(0); + this.initialized = true; + } else { + this.initialized = false; + this.stopped = true; + } + }); + }, options); + this.observer.observe(this.element.nativeElement); + } } start(time: number) {