使用ng-content的角传递模板参考>> [

问题描述 投票:0回答:1
我想通过ng-template作为嵌套在child内的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向下传递两个级别(应用程序组件>父级>子级

我想将ng-content作为嵌套在子app-component.html中的ng-content传递给[应该传递给大子代

angular angular2-template angular2-directives angular-template angular2-ngcontent
1个回答
0
投票
© www.soinside.com 2019 - 2024. All rights reserved.