Importing MouseEvent from @agm/core

3.1k Views Asked by At

I want to add markers on a Google map in angular using agm module. I've found an implementation of how to do it using the map mapClick event. But I can't import MouseEvent from @agm/core. VsCode says the module doesn't have such exported member. Searched for issues l'île that here on stack and Google but I'm kinda surprised no one raised such an issue before. Please help ! thanks in advance

Here is the code

mapClicked($event: MouseEvent) {
  this.markers.push({
    lat: $event.coords.lat,
    lng: $event.coords.lng,
    draggable: true
  });
}
1

There are 1 best solutions below

1
On

Usage will depend on the version of AGM.

Your StackBlitz example shows "@agm/core": "1.0.0"

You are likely using 3.0.0-beta.0. This should do what you are expecting

  mapClicked($event: google.maps.MouseEvent): void {
    this.markers.push({
      lat: $event.latLng.lat(),
      lng: $event.latLng.lng(),
      draggable: true
    });
  }