Googleマップはjavascriptの方法で統合されており、次のコードのようにinfowindow内でangular2関数を呼び出す必要があります。ボタンのためにinfoContent
を見てください。Googleマップのインフォ画面からAngular2関数を呼び出すにはどうすればよいですか?
for (i = 0; i < locations.length; i++) {
let locLatLng = new google.maps.LatLng(locations[i].latitude, locations[i].longitude);
let infoContent = '<button (click)="myFunction(' + locations[i].id + ')">Details ...</button>';
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));
}
残念ながら角度クリックイベント(click)="myFunction()"
はそれを行うことはできません。別の方法が必要です。誰かが私を正しい方向に向けることができれば、私はとても喜んでいます。前もって感謝します。
あなたの 'addListener()'の問題点は何ですか? 'this.map'が期待どおりに動いていない場合、下記の私の答えを見てください。他に何かありますか?いくつかのエラーメッセージ、...? –
infowindowを開くと正常に動作します。 '(クリック)'から 'onclick'に変更すると、' Uncaught ReferenceError:myFunction is not defined'が返されますが、myFunction()は角度成分の内側にあります。 –
私はあなたがイベント委任を使うべきだと思います。この質問を見ることもできますhttp://stackoverflow.com/questions/6378007/adding-event-to-element-inside-google-maps-api-infowindow – yurzui