I am looking for a way to get the AppComponent
ViewContainerRef
from a service.
I have found code online such as this code, this code or this issue, but they all are for previous versions of Angular (I am using version 6).
I would like to get this reference without having to set it myself through a setter.
Right now, I have to inject ViewContainerRef
into AppComponent
and give it to the service.
I would like to get the reference from nothing but an injected provider directly in the service, something along the lines of
constructor(
private applicationRef: ApplicationRef
) {
this.viewContainerRef = applicationRef.getAppViewRef();
}
The use-case is to create components and append them to the document, at body level or AppComponent
level ; this would allow me to create notifications, dialogs ...