diff --git a/src/google-maps/map-marker/map-marker.ts b/src/google-maps/map-marker/map-marker.ts index 0836a3456efc..9c4772978627 100644 --- a/src/google-maps/map-marker/map-marker.ts +++ b/src/google-maps/map-marker/map-marker.ts @@ -243,9 +243,7 @@ export class MapMarker implements OnInit, OnDestroy { ngOnInit() { if (this._googleMap._isBrowser) { - const combinedOptionsChanges = this._combineOptions(); - - combinedOptionsChanges.pipe(take(1)).subscribe(options => { + this._combineOptions().pipe(take(1)).subscribe(options => { // Create the object outside the zone so its events don't trigger change detection. // We'll bring it back in inside the `MapEventManager` only for the events that the // user has subscribed to. diff --git a/src/google-maps/map-polygon/map-polygon.ts b/src/google-maps/map-polygon/map-polygon.ts index 8057b635436f..9789d5374bb7 100644 --- a/src/google-maps/map-polygon/map-polygon.ts +++ b/src/google-maps/map-polygon/map-polygon.ts @@ -134,28 +134,30 @@ export class MapPolygon implements OnInit, OnDestroy { constructor(private readonly _map: GoogleMap, private readonly _ngZone: NgZone) {} ngOnInit() { - const combinedOptionsChanges = this._combineOptions(); - - combinedOptionsChanges.pipe(take(1)).subscribe(options => { - // Create the object outside the zone so its events don't trigger change detection. - // We'll bring it back in inside the `MapEventManager` only for the events that the - // user has subscribed to. - this._ngZone.runOutsideAngular(() => { - this._polygon = new google.maps.Polygon(options); + if (this._map._isBrowser) { + this._combineOptions().pipe(take(1)).subscribe(options => { + // Create the object outside the zone so its events don't trigger change detection. + // We'll bring it back in inside the `MapEventManager` only for the events that the + // user has subscribed to. + this._ngZone.runOutsideAngular(() => { + this._polygon = new google.maps.Polygon(options); + }); + this._polygon.setMap(this._map._googleMap); + this._eventManager.setTarget(this._polygon); }); - this._polygon.setMap(this._map._googleMap); - this._eventManager.setTarget(this._polygon); - }); - this._watchForOptionsChanges(); - this._watchForPathChanges(); + this._watchForOptionsChanges(); + this._watchForPathChanges(); + } } ngOnDestroy() { this._eventManager.destroy(); this._destroyed.next(); this._destroyed.complete(); - this._polygon.setMap(null); + if (this._polygon) { + this._polygon.setMap(null); + } } /** diff --git a/src/google-maps/map-polyline/map-polyline.ts b/src/google-maps/map-polyline/map-polyline.ts index 8481a0d846b5..74fdd180f56b 100644 --- a/src/google-maps/map-polyline/map-polyline.ts +++ b/src/google-maps/map-polyline/map-polyline.ts @@ -135,9 +135,7 @@ export class MapPolyline implements OnInit, OnDestroy { ngOnInit() { if (this._map._isBrowser) { - const combinedOptionsChanges = this._combineOptions(); - - combinedOptionsChanges.pipe(take(1)).subscribe(options => { + this._combineOptions().pipe(take(1)).subscribe(options => { // Create the object outside the zone so its events don't trigger change detection. // We'll bring it back in inside the `MapEventManager` only for the events that the // user has subscribed to. diff --git a/src/google-maps/map-rectangle/map-rectangle.ts b/src/google-maps/map-rectangle/map-rectangle.ts index 2e1d3ae26916..e2c7808a0178 100644 --- a/src/google-maps/map-rectangle/map-rectangle.ts +++ b/src/google-maps/map-rectangle/map-rectangle.ts @@ -142,28 +142,30 @@ export class MapRectangle implements OnInit, OnDestroy { constructor(private readonly _map: GoogleMap, private readonly _ngZone: NgZone) {} ngOnInit() { - const combinedOptionsChanges = this._combineOptions(); - - combinedOptionsChanges.pipe(take(1)).subscribe(options => { - // Create the object outside the zone so its events don't trigger change detection. - // We'll bring it back in inside the `MapEventManager` only for the events that the - // user has subscribed to. - this._ngZone.runOutsideAngular(() => { - this._rectangle = new google.maps.Rectangle(options); + if (this._map._isBrowser) { + this._combineOptions().pipe(take(1)).subscribe(options => { + // Create the object outside the zone so its events don't trigger change detection. + // We'll bring it back in inside the `MapEventManager` only for the events that the + // user has subscribed to. + this._ngZone.runOutsideAngular(() => { + this._rectangle = new google.maps.Rectangle(options); + }); + this._rectangle.setMap(this._map._googleMap); + this._eventManager.setTarget(this._rectangle); }); - this._rectangle.setMap(this._map._googleMap); - this._eventManager.setTarget(this._rectangle); - }); - this._watchForOptionsChanges(); - this._watchForBoundsChanges(); + this._watchForOptionsChanges(); + this._watchForBoundsChanges(); + } } ngOnDestroy() { this._eventManager.destroy(); this._destroyed.next(); this._destroyed.complete(); - this._rectangle.setMap(null); + if (this._rectangle) { + this._rectangle.setMap(null); + } } /** diff --git a/src/universal-app/kitchen-sink/kitchen-sink.html b/src/universal-app/kitchen-sink/kitchen-sink.html index 3de3f0502fdf..6a25ba50a688 100644 --- a/src/universal-app/kitchen-sink/kitchen-sink.html +++ b/src/universal-app/kitchen-sink/kitchen-sink.html @@ -375,7 +375,7 @@

Drag and Drop

Virtual scroll

-
+
Item #{{i}}
@@ -392,4 +392,14 @@

Google Map

strokeColor: 'grey', strokeOpacity: 0.8 }"> + +