Is it possible to prevent the destruction of Angular components when navigating?

我们两清 提交于 2020-01-12 07:30:13

问题


Assuming I have two Angular 2 components: ComponentA and ComponentB. I want to be able to navigate from ComponentA to ComponentB and then eventually back to ComponentA, while not having to reinitialize ComponentA.

In the current Angular 2 Router implementation, every time I navigate away from a component, the component gets destroyed and has to be recreated the next time I navigate to it.

I know that I can preserve the state of components by using a Service, but this seems to be more like a workaround than an actual solution to my issue. Is there any way around this?

来源:https://stackoverflow.com/questions/42265893/is-it-possible-to-prevent-the-destruction-of-angular-components-when-navigating

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