Angular 2: Swapping between different components without destroying them

后端 未结 2 1734
不知归路
不知归路 2020-12-28 17:42

I\'m trying to build a window manager with Angular 2. Basically, I want to be able to swap between windows (that are components injected in a router outlet) without losing t

2条回答
  •  半阙折子戏
    2020-12-28 18:31

    Here's how I surpassed this requirement.

    Once the route changes, the windows components are destroyed. So, to save state in between those windows instances, I had to manually store it into an injected service.

    To store and load the state for each window component, I used the life-cycle hooks that are provided by the router: onActivate(next, prev) and onDeactivate(next, prev).

    EDIT

    Meanwhile, I've opened an issue on Angular 2 github repo requesting this feature.

提交回复
热议问题