我想創建一個自己的信息窗口,我到澳鵬谷歌地圖類的父級的功能這個樣子的,其被通過點擊標記觸發:Angular2-追加變量未定義
updateDiv(location: Location) {
this.selectedLocation = location;
this.isClicked = true;
this.ID = this.selectedLocation.id;
console.log(this.ID)
$(function() {
$('.gm-style-iw').parent().append('<div class="test"><span class="ID">'+ this.ID +'</span></div>');
});
}
的console.log
顯示點擊標記的ID,但在div class='test'
中顯示爲未定義。
這是爲什麼?
或者是否也可以添加您在html模板中創建的div?它看起來像這樣:
<div *ngIf="isClicked" class="infoWindow">
<p>{{ selectedLocation.id }} {{ selectedLocation.content }}</p>
</div>
這不是工作,這是我做過什麼: '$(」克式-iw')。親本()。追加(「
你不需要的jQuery的含量可言。 [innerHtml] =「myHtml」必須放在您的模板html中。 將其視爲模型中任何變量提供的一些html代碼的主機。 –
但我將它附加到google-maps類,它覆蓋標準infoWindow:https://plnkr.co/edit/QZLs74?p=preview – Sreinieren