0

我的主页上有谷歌地图,我试图在关闭地图上显示的信息窗口时将用户路由到另一个页面:

// Google map info window code snippet from a @Directive
infowindow.addListener('closeclick', () => {
  this.router.navigate(['/users', user.id]);
});

// Component code
ngOnInit() {
  this.user$ = this.route.params.switchMap((params: Params) => this.service.getUser(params['id']));
}

// UserService
getUser(id: String): Observable < User > {
  return this.apollo.watchQuery < GetUserQueryResult > ({
    query: GetUserQuery,
    variables: {
      id: id
    }
  }).map(({
    data
  }) => data.User);
}
<div *ngIf="user$ | async as user" class="container">
  <p>user.name</p>
</div>

问题是当我到达用户页面时,除了实际单击页面一次外,div 永远不会显示。怎么了?

4

1 回答 1

0

在角度区域内运行处理程序代码应该可以帮助您

import { NgZone } from '@angular/core';

...
constructor(private zone: NgZone) {}

infowindow.addListener('closeclick', () => {
  this.zone.run(() => this.router.navigate(['/users', user.id]));
});

也可以看看

于 2017-06-10T11:36:21.197 回答