This question has been asked before and received differing answers, so I thought I'd ask again and be a little more specific. I've been going over a lot of articles from Max Koretskyi as listed in this SO question about Embedded/Host views, and it seems like it should be possible to create 2+ ViewContainerRef
s and insert the same ComponentRef<MyComponent>
instance into both of them.
This question is solved by dynamically storing a component factory in a service and detaching/attaching that component instance to a ViewContainerRef
every time a route change is made. I forked the stackblitz from that question and tried to create another one in which I attempt to load 2 views from the same instance on the same route, but it appears as if when you call viewContainerRef.insert
on a componentRef.hostView
, it looks like it automatically detaches from whatever viewRef it's currently attached to.
Is this the case, and if so, does that mean it's impossible to accomplish? Otherwise, is there another way to do this? (Short of the obvious method of creating 2 components and storing the container state elsewhere?)