I'm creating a layout with D3, and I'm trying to dynamically insert Angular components into the structure.
I've managed to get components dynamically created using a ViewContainerRef injected into the parent component:
constructor(vcRef: ViewContainerRef...
I could also have got a ViewContainerRef from a html element in the template like this:
@ViewChild('htmlElementINeed', { read: ViewContainerRef }) targetConterinRef;
However, as I'm dynamically creating the html elements wher I need my components using D3, I cannot use the injected ViewContainerRef
, or get a ViewContainerRef
from the template using @ViewChild
.
The angular documentation lists these as the two ways to access it::
To access a ViewContainerRef of an Element, you can either place a Directive injected with ViewContainerRef on the Element, or you obtain it via a ViewChild query.
Is there any way to manually create a ViewContainerRef, or get one for an element not defined in the template? Is it a restriction of Angular that I can only dynamically create components on a html element that is already in template at compile time?