Angular component are not getting destroyed

[亡魂溺海] 提交于 2020-02-26 08:42:46

问题


In angular application, every time I route to a new page, my earlier page's component is staying in memory. It's not getting destroyed and when I route back to that page it creates a new instance.

Application is not created through angular CLI. It's a custom build application using the webpack configuration provided on angular website. Actually, I am doing performance improvement of the existing angular application and this demo app I created for isolation of issue.

Github https://github.com/bytesofdhiren/angular-memory-issue

Basically, every time I route to home or register page, the application creates a new instance of the register component and home component. It's not destroying the earlier created component.


回答1:


Every component has a lifecycle you need to use:

OnDestroy();

and you need to implements the method ngOnDestroy(). Follow this




回答2:


Actually, I tried running the above Github application in production mode and the issue got resolved. But the actual issue in my production application still exists. But that is related to something else. I will post a new question for that.



来源:https://stackoverflow.com/questions/56340306/angular-component-are-not-getting-destroyed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!