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

后端 未结 5 1898
小鲜肉
小鲜肉 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 18:00

    Please try this complete solution for this question.

    var infowindow = new google.maps.InfoWindow({});
    
        for (i = 0; i < locations.length; i++) {
    
            let locLatLng = new google.maps.LatLng(locations[i].latitude, locations[i].longitude);
            let infoContent = '
    ' + '
    '+locations[i].id +'
    '+ ''+ '
    ' marker = new google.maps.Marker({ position: locLatLng, map: this.map }); google.maps.event.addListener(marker, 'click', (function(marker, i) { return function() { infowindow.setContent(infoContent); infowindow.open(this.map, marker); }; })(marker, i)); } infowindow.addListener('domready', () => { var val = document.getElementById('lt').innerHTML; document.getElementById("btn").addEventListener("click", () => { this.myFunction(val); }); });

提交回复
热议问题