Я хочу передать ng-template
как ng-content
вложенный в дочерний элемент
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;
}
директива
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
Я ожидаю, что TemplateRef
будет пройдено на два уровня вниз: app-component> parent> child