关于 Angular Component ngOnDestroy 钩子函数的调用时机
Angular 函数 关于 调用 Component 钩子 时机
2023-09-14 09:04:00 时间
我开发了一个 Angular Component,实现了 ngOnDestroy 钩子方法之后,没有找到其被调用的方法。查看这个StackOverflow链接后,得知无论是我刷新浏览器,还是从当前页面路由到一个新的页面,都不会触发 ngOnDestroy.
On refresh or when you navigate away from the current page, then ngOnDestroy won’t be called. The application will just be destroyed by the browser.
Only when Angular2 removes the component from the DOM because you move away or you call destroy() on a dynamically created component, then ngOnDestroy() is called.
只有当 Component 从 DOM 中被移除,或者显式调用一个动态创建的 Component 实例的 destroy 方法,才能触发 ngOnDestroy.
我点击 navigate to 跳转之前,DOM 元素如下图所示:
点了跳转后,browser-test 元素确实从 DOM 中消失了:
然而我在该 DOM 节点上设置的 Break on node removal 并没有触发,感觉这个跳转像是一次页面刷新:
更多Jerry的原创文章,尽在:“汪子熙”:
相关文章
- [ngx-formly] Customize Angular Formly validation messages
- [Angular] Handle HTTP Errors in Angular with HttpErrorResponse interface
- [Angular] Use Angular’s @HostBinding and :host(...) to add styling to the component itself
- SAP UI5和Angular的函数防抖(Debounce)和函数节流(Throttle)实现原理介绍
- Angular 项目里使用 scss 文件的一些技巧分享
- 关于 index.ts 在大型 Angular 项目中的应用
- Angular 依赖注入里factory函数的调用时机
- Angular input控件的click事件表达式如何被转换成JavaScript函数
- Another way to define Angular controller
- Atitit. js mvc 总结(2)----angular 跟 Knockout o99 最佳实践
- Angular 14 新的 inject 函数介绍
- Angular 下拉菜单实现的一个例子
- Angular http client发起的请求在Chrome开发者工具network标签页里观察到的界面
- Angular HTTPClient的使用方法
- Angular前端事件处理函数的形参名必须为某个硬编码值的怪事
- 集成ejs和angular