{"record":{"id":"a2aca282206c63c4","repo":"angular/components","slug":"cannot-interact-with-a-google-map-polygon-before-i","errorCode":null,"errorMessage":"Cannot interact with a Google Map Polygon before it has been initialized. Please wait for the Polygon to load before trying to interact with it.","messagePattern":"Cannot interact with a Google Map Polygon before it has been initialized\\. Please wait for the Polygon to load before trying to interact with it\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/google-maps/map-polygon/map-polygon.ts","lineNumber":260,"sourceCode":"    this._options.pipe(takeUntil(this._destroyed)).subscribe(options => {\n      this._assertInitialized();\n      this.polygon.setOptions(options);\n    });\n  }\n\n  private _watchForPathChanges() {\n    this._paths.pipe(takeUntil(this._destroyed)).subscribe(paths => {\n      if (paths) {\n        this._assertInitialized();\n        this.polygon.setPaths(paths);\n      }\n    });\n  }\n\n  private _assertInitialized(): asserts this is {polygon: google.maps.Polygon} {\n    if (typeof ngDevMode === 'undefined' || ngDevMode) {\n      if (!this.polygon) {\n        throw Error(\n          'Cannot interact with a Google Map Polygon before it has been ' +\n            'initialized. Please wait for the Polygon to load before trying to interact with it.',\n        );\n      }\n    }\n  }\n}\n","sourceCodeStart":242,"sourceCodeEnd":268,"githubUrl":"https://github.com/angular/components/blob/0411926e7d8ae06b32236ec1048a888cfad5abf2/src/google-maps/map-polygon/map-polygon.ts#L242-L268","documentation":"Thrown by MapPolygon's dev-mode assertion when its internal google.maps.Polygon is still undefined. The polygon is constructed asynchronously once the map and path inputs are ready. The guard converts a would-be TypeError into an actionable error during development.","triggerScenarios":"Calling getDraggable(), getEditable(), getPath(), getPaths(), getVisible(), or init paths before polygon construction — e.g. in ngOnInit, before map ready, or when the polygon component is not within an initialized MapComponent.","commonSituations":"Reading polygon state right after render, updating paths and immediately reading them back, Maps API still loading, conditional rendering with stale component references.","solutions":["Call polygon accessors only after map ready / ngAfterViewInit.","Set polygon state via inputs (options, path) rather than reading getters immediately after creation.","Ensure the polygon is inside a MapComponent and the API script loaded.","If mutating and reading, do it from a Google Maps event (e.g. path changed) rather than synchronously after set.","Use try-catch around accessors as a dev-time guard."],"exampleFix":"// before\nconst path = this.polygon.getPath(); // throws if too early\n// after\nthis.map.ready.subscribe(() => {\n  const path = this.polygon.getPath();\n});","handlingStrategy":"validation","validationCode":"if (!polygonRef) { /* defer */ }","typeGuard":"function isPolygonReady(p: MapPolygon | undefined): p is MapPolygon { return !!p; }","tryCatchPattern":"try {\n  const path = polygon.getPath();\n} catch (e) {\n  if ((e as Error).message.includes('Google Map Polygon')) {\n    // retry after map ready\n  } else { throw e; }\n}","preventionTips":["Access polygon getters after map ready.","Update paths via inputs and read back from map events.","Ensure polygon is inside MapComponent.","Verify API script loads.","Don't create-and-read in one tick."],"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"}