Last active
August 1, 2023 14:20
-
-
Save NetanelBasal/1e81265921551afbf45d36bd98cc7d42 to your computer and use it in GitHub Desktop.
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
openDialog<T>(dialogContent: Type<T>) { | |
const footer = document.createElement('p'); | |
footer.innerText = 'footer'; | |
const dialogContentRef = createComponent(dialogContent, { | |
environmentInjector: this.injector | |
}) | |
const dialogRef = createComponent(DialogComponent, { | |
environmentInjector: this.injector, | |
hostElement: document.getElementById('dialog-container')!, | |
projectableNodes: [ | |
// ng-content nodes | |
[dialogContentRef.location.nativeElement], | |
// second ng-content (e.g <ng-content select="footer"></ng-content>) | |
[ footer ] | |
] | |
}) | |
this.appRef.attachView(dialogRef.hostView) | |
} |
Aaaah, found the solution :
You have to attach also the view of the first component you have created to the CD cycle:
this.appRef.attachView(dialogContentRef.hostView).
If you don't do this, the dependancies of the first component won't be correctly working.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Good, but if you have dependencies in your dialogContent, it won't be 'loaded'. For exemple, if you have a Angular Material input, it won't work. It works only in you have simple HTML.