您好,我正在尝试通过 google map 信息窗口内的按钮触发事件。 问题是我无论如何都不能让它开火。
addMarket(latitud, longitud, sensorData) {
let marker = new google.maps.Marker({
draggable: false,
position: { lat: latitud, lng: longitud },
map: this.map,//set map created here
title: sensorData.sensor
});
marker.addListener('click', function () {
infowindow.open(this.map, marker);
});
let bodyMessege = 'Nombre del Sensor: ' + sensorData.sensor + '<br>' +
'Componente Descripcion: ' + sensorData.componentDesc + '<br>' +
' description: ' + sensorData.description + '<br>' +
' Tipo de sensor: ' + sensorData.type + '<br>' +
' Unidad de sensor: ' + sensorData.unit + '<br>' +
'Tipo de dato: ' + sensorData.dataType + '<br>' +
' <button ion-button (click)="this.navCtrl.push(DetalleSensorPage)" >Default</button>';
// ' <button ion-button="" onclick=console.log("log");' anda
//this.pushPage=DetalleSensorPage;
var infowindow = new google.maps.InfoWindow({
content: bodyMessege
});
欢迎任何提示,谢谢。 :)
最佳答案
我为我自己的项目找到了这个解决方案:( https://forum.ionicframework.com/t/ng-click-in-google-maps-infowindow/5537/6 )
关键元素是您在下面的 getElementbyId 中查找的 id="tap"。
let content = '<div class="infowindow"><p id="tap">your text here</p></div>';
let infoWindow = new google.maps.InfoWindow(
{
closeBoxURL: "",
content: content
}
);
infoWindow.open(this.map, marker);
google.maps.event.addListenerOnce(infoWindow, 'domready', () => {
document.getElementById('tap').addEventListener('click', () => {
//alert('Clicked');
console.log("touch");
this.closeInfoViewWindow(infoWindow);
this.openEventDetailModal(event);
});
});
希望这对您和其他人有帮助。
关于javascript - 信息窗口谷歌地图中的 Ionic 2 单击事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46741066/