Fragan
June 15, 2018, 12:41am
1
Hey, i have a googlemap infowindow and a button i want to push to another page when clicking on that button with some params, here’s my code:
google.maps.event.addListener(infowindow, 'domready', () => {
var clickableItem = document.getElementById('clickableItem');
clickableItem.addEventListener('click', () => {
this.zone.run( () => {
console.log("wlidoz "+ data[i].idprof);
this.navCtrl.push(ProfilPage, {
profilId: data[i].idprof
});
});
});
});
problem is that on the console.log data[i].idprof
, it shows undefined but this variable is defined beforegoogle.map.event.addListener
, Im sorry for my english but im really struck into this for days…
kocei
June 15, 2018, 10:11am
2
Hmm very strange way to do things, if you have a google map, why not just do this, so you dont have dom :
let marker = new google.maps.Marker({
position: positionData,
map: this.map,
});
let infowindow = new google.maps.InfoWindow({
content:'<h1>blabla</h1>'
});
marker.addListener('click', function() {
//your action
});
Can you tell us where data [i] come from ?
Fragan
June 15, 2018, 12:26pm
3
the data[i] come from database using a PHP REST API, the solution you posted is a listener for the marker, i want a listener for a button inside the infowindow
Fragan
June 15, 2018, 1:15pm
4
I fixed it, i just declared two variables before google.maps.event.addListener
let idz=data[i].idprof;
let that=this;
google.maps.event.addListener(infowindow, 'domready', () => {
var clickableItem = document.getElementById('clickableItem');
clickableItem.addEventListener('click', () => {
that.zone.run( () => {
that.navCtrl.push(ProfilPage, {
profilId: idz
});
});
});
});
If anyone has a better solution, i’d be happy to take it