angular/components · error · Error

Specified anchor does not implement the `getAnchor` method.

Error message

Specified anchor does not implement the `getAnchor` method. It cannot be used to open an info window.

What it means

MapInfoWindow.open(anchor) requires the anchor to implement the MapAnchorPoint interface, whose only requirement is getAnchor(): google.maps.LatLng | google.maps.LatLngLiteral. The dev-mode check throws when a truthy anchor is passed but it lacks getAnchor, because the info window cannot derive its position from it.

Source

Thrown at src/google-maps/map-info-window/map-info-window.ts:215

  ): void {
    this.open(
      {
        getAnchor: () => advancedMarkerElement,
      },
      undefined,
      content,
    );
  }

  /**
   * Opens the MapInfoWindow using the provided anchor. If the anchor is not set,
   * then the position property of the options input is used instead.
   */
  open(anchor?: MapAnchorPoint, shouldFocus?: boolean, content?: string | Element | Text): void {
    this._assertInitialized();

    if ((typeof ngDevMode === 'undefined' || ngDevMode) && anchor && !anchor.getAnchor) {
      throw new Error(
        'Specified anchor does not implement the `getAnchor` method. ' +
          'It cannot be used to open an info window.',
      );
    }

    const anchorObject = anchor ? anchor.getAnchor() : undefined;

    // Prevent the info window from initializing when trying to reopen on the same anchor.
    // Note that when the window is opened for the first time, the anchor will always be
    // undefined. If that's the case, we have to allow it to open in order to handle the
    // case where the window doesn't have an anchor, but is placed at a particular position.
    if (this.infoWindow.get('anchor') !== anchorObject || !anchorObject) {
      // If no explicit content is provided, it is taken from the DOM node.
      // If it is, we need to hide it so it doesn't take up space on the page.
      this._elementRef.nativeElement.style.display = content ? 'none' : '';
      if (content) {
        this.infoWindow.setContent(content);
      }

View on GitHub (pinned to 0411926e7d)

Solutions

  1. Pass a component that implements MapAnchorPoint: MatGoogleMaps-derived markers like MapMarker or MapAdvancedMarker
  2. If you must use a custom object, implement getAnchor(): google.maps.LatLng | google.maps.LatLngLiteral returning the position
  3. If you only want to position the window at coordinates, call open() with no anchor and set the infoWindow's position input instead

Example fix

// before
infoWindow.open(nativeMarker); // no getAnchor
// after
infoWindow.open(mapMarker); // Angular MapMarker implements getAnchor
// or
infoWindow.position = {lat: 1, lng: 2};
infoWindow.open();
Defensive patterns

Strategy: validation

Validate before calling

if (anchor && typeof (anchor as any).getAnchor !== 'function') {
  throw new TypeError('anchor must implement MapAnchorPoint.getAnchor()');
}

Type guard

function isMapAnchorPoint(x: unknown): x is MapAnchorPoint {
  return !!x && typeof (x as any).getAnchor === 'function';
}

Try / catch

try {
  infoWindow.open(anchor);
} catch (e) {
  console.error('Invalid anchor passed to MapInfoWindow.open:', e);
  infoWindow.position = fallbackPosition;
  infoWindow.open();
}

Prevention

When it happens

Trigger: Calling infoWindow.open(someObject) where someObject is a plain object, a wrong component instance (e.g. a GoogleMap instead of a marker wrapper), or an element, instead of a MapMarker/MapAdvancedMarker or any object implementing getAnchor().

Common situations: Passing the native google.maps.Marker directly expecting the Angular wrapper API; passing a DOM element or a custom directive instance; API confusion after migrating between marker types; typos such as passing options as the first argument.

Related errors


AI-assisted analysis of angular/components@0411926e7d (2026-08-31). Data as JSON: /api/errors/72ee970174de4164. Report an issue: GitHub.