{"record":{"id":"bf9c2ebd499fc045","repo":"angular/components","slug":"cannot-interact-with-a-google-map-info-window-befo","errorCode":null,"errorMessage":"Cannot interact with a Google Map Info Window before it has been initialized. Please wait for the Info Window to load before trying to interact with it.","messagePattern":"Cannot interact with a Google Map Info Window before it has been initialized\\. Please wait for the Info Window to load before trying to interact with it\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/google-maps/map-info-window/map-info-window.ts","lineNumber":274,"sourceCode":"    this._options.pipe(takeUntil(this._destroy)).subscribe(options => {\n      this._assertInitialized();\n      this.infoWindow.setOptions(options);\n    });\n  }\n\n  private _watchForPositionChanges() {\n    this._position.pipe(takeUntil(this._destroy)).subscribe(position => {\n      if (position) {\n        this._assertInitialized();\n        this.infoWindow.setPosition(position);\n      }\n    });\n  }\n\n  private _assertInitialized(): asserts this is {infoWindow: google.maps.InfoWindow} {\n    if (typeof ngDevMode === 'undefined' || ngDevMode) {\n      if (!this.infoWindow) {\n        throw Error(\n          'Cannot interact with a Google Map Info Window before it has been ' +\n            'initialized. Please wait for the Info Window to load before trying to interact with ' +\n            'it.',\n        );\n      }\n    }\n  }\n}\n","sourceCodeStart":256,"sourceCodeEnd":283,"githubUrl":"https://github.com/angular/components/blob/0411926e7d8ae06b32236ec1048a888cfad5abf2/src/google-maps/map-info-window/map-info-window.ts#L256-L283","documentation":"Thrown by MapInfoWindow's dev-mode assertion when its internal google.maps.InfoWindow is still undefined. The InfoWindow object is created asynchronously once the component initializes within a map. The library asserts before every interaction so developers get a clear message rather than a TypeError on undefined.","triggerScenarios":"Calling open(), close(), getContent(), getPosition(), getZIndex(), or triggering _watchForOptionsChanges before the infoWindow object exists — e.g. calling open() in ngOnInit, before the hosting map is rendered, or when the InfoWindow is used outside a MapComponent context that initializes it.","commonSituations":"Programmatically opening an info window immediately after page load, opening from an event that fires before view init, rendering MapInfoWindow outside <map> or before Google Maps API load, toggling *ngIf that recreates the window while holding a stale reference.","solutions":["Call open()/close() only after the map and info window are initialized — e.g. inside map.ready subscription or ngAfterViewInit.","If opening from an external event, guard with a flag set after first successful initialization, or check the component reference exists before calling.","Ensure MapInfoWindow is placed inside a MapComponent so _initialize runs with a valid map.","Ensure the Google Maps JS API has loaded; without it initialization never completes.","Catch the error around open/close calls to avoid breaking event handlers in dev."],"exampleFix":"// before\nngOnInit() {\n  this.infoWindow.open(this.map.googleMap); // throws: not yet initialized\n}\n// after\nngAfterViewInit() {\n  this.map.ready.subscribe(() => this.infoWindow.open(this.map.googleMap));\n}","handlingStrategy":"try-catch","validationCode":"if (!infoWindowRef) { /* defer open */ }","typeGuard":"function isInfoWindowReady(w: MapInfoWindow | undefined): w is MapInfoWindow { return !!w; }","tryCatchPattern":"try {\n  infoWindow.open(map.googleMap, anchor);\n} catch (e) {\n  if ((e as Error).message.includes('Info Window')) {\n    this.map.ready.subscribe(() => infoWindow.open(map.googleMap, anchor));\n  } else { throw e; }\n}","preventionTips":["Open/close info windows only after map.ready.","Keep MapInfoWindow inside the MapComponent template.","Avoid opening windows from events that fire before view init.","Use a ready flag set after first successful open.","Re-acquire component references when *ngIf recreates the window."],"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"}