Skip to content

Commit 90c3747

Browse files
author
Markus Block
committed
Added PlatformBrowser check for IntersectionObserver to support SSR
1 parent e5c16a2 commit 90c3747

File tree

2 files changed

+25
-25
lines changed

2 files changed

+25
-25
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@omnedia/ngx-globe",
33
"description": "A simple component library to create a container with an animated and interactive globe.",
4-
"version": "1.0.2",
4+
"version": "1.0.3",
55
"peerDependencies": {
66
"@angular/common": "^18.2.0",
77
"@angular/core": "^18.2.0",

src/lib/ngx-globe.component.ts

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
1-
import { CommonModule } from "@angular/common";
2-
import {
3-
AfterViewInit,
4-
Component,
5-
ElementRef,
6-
Input,
7-
OnDestroy,
8-
ViewChild,
9-
} from "@angular/core";
1+
import {CommonModule, isPlatformBrowser} from "@angular/common";
2+
import {AfterViewInit, Component, ElementRef, Inject, Input, OnDestroy, PLATFORM_ID, ViewChild,} from "@angular/core";
103
import createGlobe from "cobe";
114
import Phenomenon from "phenomenon";
12-
import { COBEOptionsPart, GlobeOptions } from "./ngx-globe.types";
5+
import {COBEOptionsPart, GlobeOptions} from "./ngx-globe.types";
136

147
@Component({
158
selector: "om-globe",
@@ -74,16 +67,16 @@ export class NgxGlobeComponent implements AfterViewInit, OnDestroy {
7467
glowColor: [1, 1, 1],
7568
offset: [0, 0],
7669
markers: [
77-
{ location: [14.5995, 120.9842], size: 0.03 },
78-
{ location: [19.076, 72.8777], size: 0.1 },
79-
{ location: [23.8103, 90.4125], size: 0.05 },
80-
{ location: [30.0444, 31.2357], size: 0.07 },
81-
{ location: [39.9042, 116.4074], size: 0.08 },
82-
{ location: [-23.5505, -46.6333], size: 0.1 },
83-
{ location: [19.4326, -99.1332], size: 0.1 },
84-
{ location: [40.7128, -74.006], size: 0.1 },
85-
{ location: [34.6937, 135.5022], size: 0.05 },
86-
{ location: [41.0082, 28.9784], size: 0.06 },
70+
{location: [14.5995, 120.9842], size: 0.03},
71+
{location: [19.076, 72.8777], size: 0.1},
72+
{location: [23.8103, 90.4125], size: 0.05},
73+
{location: [30.0444, 31.2357], size: 0.07},
74+
{location: [39.9042, 116.4074], size: 0.08},
75+
{location: [-23.5505, -46.6333], size: 0.1},
76+
{location: [19.4326, -99.1332], size: 0.1},
77+
{location: [40.7128, -74.006], size: 0.1},
78+
{location: [34.6937, 135.5022], size: 0.05},
79+
{location: [41.0082, 28.9784], size: 0.06},
8780
],
8881
};
8982

@@ -94,13 +87,20 @@ export class NgxGlobeComponent implements AfterViewInit, OnDestroy {
9487
private intersectionObserver?: IntersectionObserver;
9588
private isAnimating = false;
9689

90+
constructor(
91+
@Inject(PLATFORM_ID) private platformId: object
92+
) {
93+
}
94+
9795
ngAfterViewInit(): void {
9896
this.initGlobe();
9997

100-
this.intersectionObserver = new IntersectionObserver(([entry]) => {
101-
this.renderContents(entry.isIntersecting);
102-
});
103-
this.intersectionObserver.observe(this.globeCanvas.nativeElement);
98+
if (isPlatformBrowser(this.platformId)) {
99+
this.intersectionObserver = new IntersectionObserver(([entry]) => {
100+
this.renderContents(entry.isIntersecting);
101+
});
102+
this.intersectionObserver.observe(this.globeCanvas.nativeElement);
103+
}
104104
}
105105

106106
ngOnDestroy(): void {

0 commit comments

Comments
 (0)