3

I'm rending map using this angular library for mapbox ngx-mapbox-gl I'm showing a popup on mouseenter event.

mapInstance.on("mouseenter", "scoots_layers", function (e) {
  var _lat = e.lngLat.lat;
  var _lng = e.lngLat.lng;
  var coordinates = [_lng, _lat];
  this.popup = new Popup({
    closeButton: true,
    closeOnClick: true,
  });
  this.popup.setLngLat(coordinates)
    .setHTML('<button (click)="goToPage()">Hello </button>')
    .addTo(mapInstance);
});

Popup is working fine. But the click event of button is not triggered.

Usman Ali
  • 61
  • 4

1 Answers1

2

Maybe if you do it this way it works

 this.popup.setLngLat(coordinates)
.setHTML('<button  id="myBtn">Hello </button>')
.addTo(mapInstance);

});

and in your ts file

document.getElementById("myBtn").addEventListener("click", function(){
  alert('say something...');
}); 
Ehsan Kiani
  • 3,050
  • 1
  • 17
  • 19