How could I call a Angular2 function from a Google Map infowindow?

后端 未结 5 1901
小鲜肉
小鲜肉 2021-02-10 17:17

Google map is integrated the javascript way and I want to call a angular2 function inside an infowindow like the following code. Take a look at infoContent for the

5条回答
  •  执念已碎
    2021-02-10 17:40

    Here is my solution. First, I set id to button in info window. After that, I caught 'domready' event for info window which means: all the HTML has been received and parsed by the browser into the DOM tree which can now be manipulated. And then with getElementById accessed to button and add event 'click'. Here you can call your function defined in ts file.

    const infoWindowContent = '
    ' + community.typeOfCommunity + '
    ' + '

    ' + community.address.name + ' ' + community.streetNumber + ', ' + community.city + '

    ' + '

    Manager: ' + community.manager.fullName + '

    ' + ''; const infoWindow = new google.maps.InfoWindow({ content: infoWindowContent }); marker.addListener('click', () => { infoWindow.open(this.map, marker); }); infoWindow.addListener('domready', () => { document.getElementById("infoWindowButton").addEventListener("click", () => { this.myFunction(); }); });

提交回复
热议问题