【发布时间】:2018-06-30 17:27:52
【问题描述】:
我有一个组件 A 和 B
<div class="A">
<div class="A1"></div>
<div class="A2"></div>
</div>
<div class="B">
<!--want to display <div class="A1"></div> here-->
</div>
组件 B 不包含组件 A 或其他方式
<componentA></componentA>
<componentB></componentB>
我尝试将 <div class="A1"></div> 包装到 ng-template 中,然后在 componentB 中进行查询,但它始终是 undefined:
@ViewChild('templ') templ: TemplateRef<any>;
然后我意识到@ViewChild是查询子组件,那么<ng-template>不是子组件怎么查询和渲染呢?
【问题讨论】:
标签: angular ng-template ng-content