Askanison4 Askanison4 - 28 days ago 7x
TypeScript Question

Have more than one active module in Angular 2

Angular 2 final has been released and I've been playing around with the final router release.

A good example of the router in action can be found here:

I was wondering if there's any mechanism for keeping the current module rendered in the DOM (but hidden) while loading in a new one on top? The use case here is that perhaps a user may be using an Admin-type module and realise they need to create some asset (perhaps a user) so jump to a Users module to create; before hopping back to where they were in the Admin module.

In this scenario, the user could be at some deep-linked section of the Admin module and it would be very strange behaviour for them to lose what they were doing.

Is this possible? From all I've done so far, I've seen that the modules presented in the

tags get dumped off the DOM completely.



Currently components added by the router are discarded when the route is changed. This is planned to be made configurable eventually.

If you keep data (model) in shared services (that are not discarded) instead of the component itself, then the user gets back the original view when navigating back to a previous route.

The services needs to be provided on a component that isn't removed by the router. The root component or providers in an @NgModule() that is not lazy-loaded would work.