Skip to content

Instantly share code, notes, and snippets.

@ericjeker
Created March 13, 2020 06:42
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ericjeker/aae7048bd1a540240fb9078c3b995e55 to your computer and use it in GitHub Desktop.
Save ericjeker/aae7048bd1a540240fb9078c3b995e55 to your computer and use it in GitHub Desktop.
TemplateRef and ngTemplateOutlet using ContentChild in Angular
@Component({
selector: 'app-my-content',
template: '<ng-container *ngTemplateOutlet="tplRef"></ng-container>',
})
class MyContent {
@ContentChild('myContent', {static: true}) tplRef: TemplateRef<any>;
}
<app-my-content>
<ng-template #myContent>
<app-my-other-component>Ouch!</app-my-other-component>
</ng-template>
</app-my-content>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment