Last active
August 13, 2023 09:18
-
-
Save GreenFlag31/f77e459037f1879fc87e773f1f72571d to your computer and use it in GitHub Desktop.
modal service class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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