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

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

问题描述

我正在使用此角度库出租地图箱 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文件中

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

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

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