如何保持Angular 4模板与谷歌地图点击事件同步
我需要依赖GoogleMapsAPI,它的事件与Angular 4中的变化检测系统不同步。如何让它们同步如何保持Angular 4模板与谷歌地图点击事件同步,angular,google-maps,events,rxjs,Angular,Google Maps,Events,Rxjs,我需要依赖GoogleMapsAPI,它的事件与Angular 4中的变化检测系统不同步。如何让它们同步 location = 'some initial value'; ngOnInit() { ... google.maps.event.addListener(this.map, 'click', this.updateLocation.bind(this)); } private updateLocation(event) { this.location = event.l
location = 'some initial value';
ngOnInit() {
...
google.maps.event.addListener(this.map, 'click', this.updateLocation.bind(this));
}
private updateLocation(event) {
this.location = event.latLng.toString();
console.log(this.location);
}
我的模板总是显示初始值。在控制台中,我确实看到了更新的值
在AngularJS中,我将使用$applyAsync。我想用RxJS用“角度4方式”解决这个问题,但我不知道如何解决
请参阅此处的完整示例:在angular zone内运行代码可以帮助您
constructor(private zone: NgZone) {}
google.maps.event.addListener(this.map, 'click',
(e) => this.zone.run(() => this.updateLocation(e)));