Currently, I am searching for a method to obtain the ViewContainerRef
of the AppComponent
using a service.
I have come across various sources online such as this article, this blog post, and this forum thread, but they are all tailored to older versions of Angular (I am utilizing version 6).
My goal is to retrieve this reference without manually setting it through a setter function.
Currently, my workaround involves injecting ViewContainerRef
into AppComponent
and passing it to the service.
Instead, I aim to access the reference directly in the service by using an injected provider. For instance:
constructor(
private applicationRef: ApplicationRef
) {
this.viewContainerRef = applicationRef.getAppViewRef();
}
This functionality is needed for dynamically creating components and adding them to the document, either at the body level or within the AppComponent
. This would enable me to generate notifications, dialogs, and more.