I want to pass ng-template
as ng-content
nested inside child
app-component.html
<app-parent>
<ng-template appTemplateRetrieval>
<div>this should be passed to grand child</div>
</ng-template>
</app-parent>
parent-component.html
<app-child>
{{directivesTemplate}}
</app-child>
parent-component.ts
@ContentChild(TemplateRetrievalDirective, {static: false}) tplRetDir: TemplateRetrievalDirective;
get directivesTemplate(): TemplateRef<any> {
return this.tplRetDir && this.tplRetDir.template;
}
directive
export class TemplateRetrievalDirective {
constructor(public template: TemplateRef<any>) { }
}
child-component.ts
@ContentChild(TemplateRef, {static: true}) contentTpl: TemplateRef<any>;
ngAfterContentInit() {
console.log(this.contentTpl) // logs to console: undefined
}
stackblitz: https://stackblitz.com/edit/angular-cuipde
I expect TemplateRef
to be passed two levels down: app-component > parent > child