角2:不同组件之间交换,不破坏他们 [英] Angular 2: Swapping between different components without destroying them

查看:152
本文介绍了角2:不同组件之间交换,不破坏他们的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图建立与角基本上,我希望能够不失其状态窗口(即在一个路由器的出口注入组件)之间切换窗口管理器。举例来说,我在编辑一个产品信息表,当我更改为客户的名单,那么我回来的产品形式,我觉得它在相同的状态......这可能吗?

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 their states. For instance, I'm editing a product information form when I change to a customers' list, then I come back to the product form and I find it in the same state... Is it possible?

推荐答案

下面就是我超越了这个要求。

Here's how I surpassed this requirement.

一旦路由变化,Windows组件被破坏。所以,保存状态在这些窗口实例之间,我不得不手动将其存储到注射服务。

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.

要存储和加载状态,每个窗口组件,我用路由器提供的生命周期挂钩:onActivate(接下来,preV)和onDeactivate(接下来,preV)

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).

修改

同时,我对角2 github上回购打开了一个问题请求此功能

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

这篇关于角2:不同组件之间交换,不破坏他们的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆