【发布时间】:2017-09-05 09:45:46
【问题描述】:
嗨,我已经搜索了好几个小时,希望你能帮助我:)
想法
如果您单击谷歌地图上的信息窗口,我想显示一个页面。 (使用 Ionic 2 中的 ModalController)
问题
点击不起作用..
var infoWindow = new google.maps.InfoWindow({
content: '<h2 (click)="goToProductPage(product)">Click me</h2>'
});
goToProductPage(product :any){
let modal = this.modalCtrl.create(ProductPage, product);
modal.present();
}
遗憾的是,这不起作用,我也尝试使用内容节点,使用 onclick="",使用 javascript 函数..
这是另一个question with the same problem 未解决的问题。
最好的问候, 路易斯
编辑
setProductMarker(product :any, productLocation :any){
var contentWindow = "<h2 id='clickableItem'>Click me</h2>" + product.productName + "<img src='" + product.imgUrl + "' width='60' height='60' /> <br/>" + product.date
var clickableItem = document.getElementById('clickableItem');
clickableItem.addEventListener('click' , () => {
this.goToProductPage(product);
});
var productMarker = new google.maps.Marker({
position: new google.maps.LatLng(JSON.parse(productLocation).latitude, JSON.parse(productLocation).longitude),
map: this.map,
title:"Product"
})
var infoWindow = new google.maps.InfoWindow({
content: contentWindow
});
infoWindow.addListener('click', () => {
alert("yeah");
console.log("yeah");
});
productMarker.addListener('click', event => {
infoWindow.open(this.map, productMarker);
this.productNow = product;
});
}
【问题讨论】:
-
我不确定
(click)="goToProductPage(product)"是否可以这样触发。你可以试试这个吗?为我工作。infoWindow.addEventListener('click', () => {})。只是告诉你,在我的例子中,我有一个从 DOM 准备的 html 元素,而不是 infoWindow。
标签: javascript google-maps angular typescript ionic2