Skip to content
This repository was archived by the owner on Jun 23, 2025. It is now read-only.

Commit 7e408e9

Browse files
pertsengadoom777
authored andcommitted
Adopted fix for angular universal support (#1747)
Fixes #1052
1 parent a1a17a6 commit 7e408e9

File tree

1 file changed

+13
-3
lines changed
  • packages/core/directives

1 file changed

+13
-3
lines changed

packages/core/directives/map.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { Component, ElementRef, EventEmitter, Input, NgZone, OnChanges, OnDestroy, OnInit, Output, SimpleChanges } from '@angular/core';
1+
import { isPlatformServer } from '@angular/common';
2+
import { Component, ElementRef, EventEmitter, Inject, Input, NgZone, OnChanges, OnDestroy, OnInit, Output, PLATFORM_ID, SimpleChanges } from '@angular/core';
23
import { Subscription } from 'rxjs';
34

45
import { MouseEvent } from '../map-types';
@@ -378,11 +379,20 @@ export class AgmMap implements OnChanges, OnInit, OnDestroy {
378379
*/
379380
@Output() tilesLoaded: EventEmitter<void> = new EventEmitter<void>();
380381

381-
constructor(private _elem: ElementRef, private _mapsWrapper: GoogleMapsAPIWrapper, protected _fitBoundsService: FitBoundsService, private _zone: NgZone) {
382-
}
382+
constructor(
383+
private _elem: ElementRef,
384+
private _mapsWrapper: GoogleMapsAPIWrapper,
385+
@Inject(PLATFORM_ID) private _platformId: Object,
386+
protected _fitBoundsService: FitBoundsService,
387+
private _zone: NgZone
388+
) {}
383389

384390
/** @internal */
385391
ngOnInit() {
392+
if (isPlatformServer(this._platformId)) {
393+
// The code is running on the server, do nothing
394+
return;
395+
}
386396
// todo: this should be solved with a new component and a viewChild decorator
387397
const container = this._elem.nativeElement.querySelector('.agm-map-container-inner');
388398
this._initMapInstance(container);

0 commit comments

Comments
 (0)