Angular Google 地图 mapClick() 事件无效

Angular Google Maps mapClick() event not working

使用 Angular Google 地图 (AGM),我试图在点击地图时添加一个新标记。为此,我添加了一个事件 mapClick,它将带有坐标的事件发送到 addMarker 方法。

<agm-map [latitude]="location.latitude" [longitude]="location.longitude" (mapClick)="addMarker($event.coords.lat, $event.coords.lng)">
<agm-marker [latitude]="location.latitude" [longitude]="location.longitude"></agm-marker>
import { Component, OnInit } from '@angular/core';

import { Location } from '../models/map-model';

@Component({
  selector: 'app-map',
  templateUrl: './map.component.html',
  styleUrls: ['./map.component.scss']
})
export class MapComponent implements OnInit {
  public location: Location;
  public markers: [];

  constructor() { /*empty*/ }

  ngOnInit(): void {
    this.location = {
      latitude: -28.68352,
      longitude: -147.20785
    }
  }

  addMarker(latitude: number, longitude: number) {
    console.log(`latitude: ${latitude}, longitude: ${longitude}`);
  }
}

问题:

enter image description here

这是最新发布版本中的 bug3.0.0-beta.0

它显然已修复但尚未发布。

您可以恢复到 ^1.1.0

或实施 workaround suggested in the issue.