Last active
March 13, 2020 06:38
-
-
Save ericjeker/18bb6e3a3c3cec0f6387798b31fe715d to your computer and use it in GitHub Desktop.
Simple TemplateRef and ngTemplateOutlet usage in Angular
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
<app-my-content tplRef="myContent"></app-my-content> | |
<ng-template #myContent> | |
<app-my-other-component>Hello world!</app-my-other-component> | |
</ng-template> |
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
@Component({ | |
selector: 'app-my-content', | |
template: '<ng-container *ngTemplateOutlet="tplRef"></ng-container>', | |
}) | |
class MyContent { | |
@Input() tplRef: TemplateRef<any>; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment