【发布时间】:2019-11-13 03:26:35
【问题描述】:
在一个特定的路由中,我正在加载一个订阅 router.events 的组件,以检测该组件中的任何路由更改(如 queryparams)。当我转到加载不同组件的不同路由时,即使在加载新组件之前在第一个组件上调用了 ngOnDestroy 生命周期挂钩,仍然会调用第一个组件的 router.event。我的问题是调用 ngOnDestroy 这意味着第一个组件应该销毁。那么为什么在每次路由更改时仍然调用订阅的 router.events 。
this.router.events.subscribe((event: any) => {
if (event instanceof NavigationEnd) {
this.applicationItemIdChange = this.route.snapshot.params['id'];
if (this.applicationItemId && this.applicationItemIdChange && this.applicationItemIdChange !== this.applicationItemId) {
this.ngOnInit();
}
}
});
【问题讨论】:
标签: angular