我的主页上有谷歌地图,我试图在关闭地图上显示的信息窗口时将用户路由到另一个页面:
// 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 永远不会显示。怎么了?