在这种情况下,app-child无法更改,这意味着您只能操作app-parent.我的意见是找到一种方法在app-child中插入模板,是否有类似Renderer2.insert(parent, newItem, childRef)或其他解决方案的功能?
有关详细信息,请参阅https://stackblitz.com/edit/insert-template-to-child-component.
app.component.html
<app-parent>
<ng-template #childTemplate>
how to insert this template in app-child
</ng-template>
</app-parent>
Run Code Online (Sandbox Code Playgroud)
parent.component.html
<app-child>
<!-- <ng-template #childTemplate>
this is work, but I need to input the template in app-parent content
</ng-template> -->
</app-child>
Run Code Online (Sandbox Code Playgroud)
child.component.html
<ng-container [ngTemplateOutlet]="childTemplate"></ng-container>
Run Code Online (Sandbox Code Playgroud) angular ×1