I am trying to call a function from a Google Maps API InfoWindows, but it shows me the following error:
(index):1 Uncaught ReferenceError: ir is not defined at HTMLButtonElement.onclick ((index):1)
It seems to say that the function ir()
is not defined.
This is my code:
addMarker(position,map,title){
var marker = new google.maps.Marker({
position,
map,
title
});
var infoWindow = new google.maps.InfoWindow({
content:" "
});
marker.addListener('click',function(){
infoWindow.setContent('<h1> '+ title +'</h1>' +
'<button class="mapaboton" onclick="ir()">Ver Detalles</button>');
infoWindow.open(map,marker);
});
}
Function ir()
which I do have defined:
ir(){
console.log("vamos");
}
When I click the button that I create in it, infowindows
it shows me the error. I've been researching and can't find the answer.
Basically what I'm trying to do is this
I finally found the solution
basically it is to put an id to the button
and then
an addListenerOnce event
The thing is that go() is not a function, it's a method of your component, that's why you didn't write
function
in front (it's not because it's typescript , javascript has the same syntax):Therefore, you have to define the function outside the component to make it accessible: