I am trying to open a a component in new window for which has multiple child components.
Below is the code I am using, but the new opened window is not getting bootstrapped. What can I do so that its bootstrapped and can access other components? Is there any other way to do so in angular?
constructor(private r: ComponentFactoryResolver, private
viewContainerRef: ViewContainerRef) { }
public windowReference: any;
ngAfterViewInit() {
setTimeout(() => {
//create the component dynamically
const factory = this.r.resolveComponentFactory(AChildComponent);
const comp: ComponentRef<AChildComponent> =
this.viewContainerRef.createComponent(factory);
//in case you also need to inject an input to the child,
//like the windows reference
comp.instance.someInputField = this.windowReference.document.body;
//add you freshly baked component on the windows
this.windowReference.document.body.appendChild(comp.location.nativeElement);
});
}
ngOnInit() {
//create the windows and save the reference
this.windowReference = window.open('', '_blank', 'toolbar=0, width=800, height=400');
}
}```
question from:
https://stackoverflow.com/questions/66058748/angular-component-in-new-window-not-getting-bootstrapped 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…