{"record":{"id":"a2ea70d50140c9ef","repo":"angular/components","slug":"cannot-interact-with-a-google-map-marker-before-it-a2ea70","errorCode":null,"errorMessage":"Cannot interact with a Google Map Marker before it has been initialized. Please wait for the Marker to load before trying to interact with it.","messagePattern":"Cannot interact with a Google Map Marker before it has been initialized\\. Please wait for the Marker to load before trying to interact with it\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/google-maps/map-marker/map-marker.ts","lineNumber":495,"sourceCode":"  /** Creates a combined options object using the passed-in options and the individual inputs. */\n  private _combineOptions(): google.maps.MarkerOptions {\n    const options = this._options || DEFAULT_MARKER_OPTIONS;\n    return {\n      ...options,\n      title: this._title || options.title,\n      position: this._position || options.position,\n      label: this._label || options.label,\n      clickable: this._clickable ?? options.clickable,\n      map: this._googleMap.googleMap,\n      icon: this._icon || options.icon,\n      visible: this._visible ?? options.visible,\n    };\n  }\n\n  private _assertInitialized(): asserts this is {marker: google.maps.Marker} {\n    if (typeof ngDevMode === 'undefined' || ngDevMode) {\n      if (!this.marker) {\n        throw Error(\n          'Cannot interact with a Google Map Marker before it has been ' +\n            'initialized. Please wait for the Marker to load before trying to interact with it.',\n        );\n      }\n    }\n  }\n}\n","sourceCodeStart":477,"sourceCodeEnd":503,"githubUrl":"https://github.com/angular/components/blob/0411926e7d8ae06b32236ec1048a888cfad5abf2/src/google-maps/map-marker/map-marker.ts#L477-L503","documentation":"Thrown by MapMarker's dev-mode assertion when its internal google.maps.Marker is still undefined. The marker is created asynchronously after the map and marker inputs are ready. The guard makes premature interaction fail with a clear, searchable message in dev mode.","triggerScenarios":"Calling getAnimation(), getClickable(), getCursor(), getDraggable(), getIcon() (and other accessors routed through _assertInitialized) before marker creation — typically in ngOnInit, immediately after dynamic creation, or when the marker isn't attached to an initialized map.","commonSituations":"Reading marker properties right after mounting, *ngFor markers whose accessors are read by a parent in the same change-detection pass, Google Maps API still loading, marker used outside a MapComponent.","solutions":["Defer accessor calls to after view init / map ready (subscribe to MapComponent.ready).","Interact with markers via template bindings (position/options inputs) instead of imperative getters during setup.","Ensure the marker is inside a MapComponent and the Maps API loaded.","If reading marker state in event handlers, only handle events after the marker signals ready (ngAfterViewInit).","Wrap getter calls in try-catch in dev builds for resilience."],"exampleFix":"// before\nngOnInit() {\n  const draggable = this.marker.getDraggable(); // throws\n}\n// after\nngAfterViewInit() {\n  this.map.ready.subscribe(() => {\n    const draggable = this.marker.getDraggable();\n  });\n}","handlingStrategy":"validation","validationCode":"if (!markerRef) { /* defer accessor call */ }","typeGuard":"function isMarkerReady(m: MapMarker | undefined): m is MapMarker { return !!m; }","tryCatchPattern":"try {\n  const icon = marker.getIcon();\n} catch (e) {\n  if ((e as Error).message.includes('Google Map Marker')) {\n    // defer to map ready\n  } else { throw e; }\n}","preventionTips":["Read marker state after ngAfterViewInit or map ready.","Configure markers via inputs, not imperative calls at mount.","Keep markers inside MapComponent.","Handle marker events only after ready flag set.","Avoid stale refs after *ngIf recreation."],"tags":["angular","google-maps","lifecycle","initialization"],"backgroundTag":"component-accessed-before-initialization","analyzedSha":"0411926e7d8ae06b32236ec1048a888cfad5abf2","analyzedAt":"2026-08-31T11:58:23.400Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}