我想创建一个自己的信息窗口,我到澳鹏谷歌地图类的父级的功能这个样子的,其被通过点击标记触发: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