重新加载页面时 ngOnDestroy
ngOnDestroy while reloading page
我正在尝试理解和试验 Angular 生命周期挂钩。
关于ngOnDestroy
,官方文档中说:
A lifecycle hook that is called when a directive, pipe, or service is destroyed. Use for any custom cleanup that needs to occur when the instance is destroyed.
因此,我可以在重定向页面时触发 ngOnDestroy
事件。奇怪的是,我在重新加载页面时无法触发 ngOnDestroy
。当我重新加载页面时,它不会破坏我的指令和服务吗?为什么 ngOnDestroy
没有在页面重新加载时触发?
问题已经回答:
ngOnDestroy
only fires when the component is destroyed inside the angular workflow. However, refreshing the page is outside of the workflow
ngOnDestroy 仅当组件或服务在 angular 工作流中被销毁时才会被触发。因此,重新加载或刷新页面超出了范围,因此不会触发此方法。
我正在尝试理解和试验 Angular 生命周期挂钩。
关于ngOnDestroy
,官方文档中说:
A lifecycle hook that is called when a directive, pipe, or service is destroyed. Use for any custom cleanup that needs to occur when the instance is destroyed.
因此,我可以在重定向页面时触发 ngOnDestroy
事件。奇怪的是,我在重新加载页面时无法触发 ngOnDestroy
。当我重新加载页面时,它不会破坏我的指令和服务吗?为什么 ngOnDestroy
没有在页面重新加载时触发?
问题已经回答
ngOnDestroy
only fires when the component is destroyed inside the angular workflow. However, refreshing the page is outside of the workflow
ngOnDestroy 仅当组件或服务在 angular 工作流中被销毁时才会被触发。因此,重新加载或刷新页面超出了范围,因此不会触发此方法。