Change Detect not working in directive event ouput in Angular 2

前端 未结 2 1263
臣服心动
臣服心动 2021-01-22 06:28

I use this directive. However, on the setAddress event output, no changes are detected in my component. The view is not updated. I d\'ont understand.

For test, if i remo

2条回答
  •  花落未央
    2021-01-22 07:05

    Handler for place_changed is running outside angular zone. You need to run it like this:

    constructor(..., private zone: NgZone) {
      ...
      google.maps.event.addListener(this.autocomplete, 'place_changed', ()=> {
        var place = this.autocomplete.getPlace();
        this.zone.run(() => this.invokeEvent(place)); // run inside angular zone
      });
    

提交回复
热议问题