未触发弹出窗口内的 ngx-mapbox-gl 按钮单击事件 [英] ngx-mapbox-gl button click event inside a popup is not triggered

查看:37
本文介绍了未触发弹出窗口内的 ngx-mapbox-gl 按钮单击事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用这个角度库为 mapbox 绘制地图 ngx-mapbox-gl我正在显示关于 mouseenter 事件的弹出窗口.

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.

推荐答案

也许如果你这样做,它会起作用

Maybe if you do it this way it works

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

});

并在您的 ts 文件中

and in your ts file

document.getElementById("myBtn").addEventListener("click", function(){
  alert('say something...');
}); 

这篇关于未触发弹出窗口内的 ngx-mapbox-gl 按钮单击事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆