Skip to content

Instantly share code, notes, and snippets.

@GreenFlag31
Last active August 13, 2023 09:18
Show Gist options
  • Save GreenFlag31/f77e459037f1879fc87e773f1f72571d to your computer and use it in GitHub Desktop.
Save GreenFlag31/f77e459037f1879fc87e773f1f72571d to your computer and use it in GitHub Desktop.
modal service class
private openWithComponent(component: Type<unknown>) {
// create the desired component, the content of the modal box
const newComponent = createComponent(component, {
environmentInjector: this.injector,
});
// create the modal component and project the instance of the desired component in the ng-content
this.newModalComponent = createComponent(ModalComponent, {
environmentInjector: this.injector,
projectableNodes: [[newComponent.location.nativeElement]],
});
document.body.appendChild(this.newModalComponent.location.nativeElement);
// Attach views to the changeDetection cycle
this.appRef.attachView(newComponent.hostView);
this.appRef.attachView(this.newModalComponent.hostView);
}
close() {
this.newModalComponent.instance.close();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment