【发布时间】:2018-05-28 09:52:10
【问题描述】:
我正在尝试将一些角度属性与 *ngIf 绑定,但根本不起作用。
我给你看我的代码,首先是我的 loadMap 函数:
loadMap() {
this.map = new google.maps.Map(document.getElementById('map'), this.mapOptions);
google.maps.event.addListenerOnce(this.map, 'idle', ()=>{
this.addMarkers()
});
}
还有 addMarkers() 函数:
addMarkers() {
var me = this;
this.restaurants.map( restaurant => {
new google.maps.Marker({
position: new google.maps.LatLng(restaurant.location.latitude, restaurant.location.longitude),
map: this.map,
animation: google.maps.Animation.DROP,
name: restaurant.id
})
.addListener('click', function() {
me.ngZone.run(() => {
this.restaurantSelected = restaurant
console.log(this.restaurantSelected);
});
});
});
}
这个问题甚至在 ngZone.run() 内部也是引用标记而不是组件。我不知道我该如何解决这个问题。
提前谢谢你。
问候。
【问题讨论】:
标签: angular google-maps listener google-maps-markers