Angular 嵌套在ng内容中的目标组件

Angular 嵌套在ng内容中的目标组件,angular,Angular,我试图将嵌套在ng content中的组件作为目标,并像ViewChild那样处理它。例如,ComponentB放在ComponentA的ng content中 我试图做的类似于: @ViewChild('componentB')componentBViewChild:componentB; 因此,我可以使用它的功能,如: this.componentBViewChild.functionFoo(); 问题是,我无法添加引用以将嵌套组件作为目标 欢迎提供任何帮助使用@ContentChild

我试图将嵌套在
ng content
中的组件作为目标,并像
ViewChild
那样处理它。例如,
ComponentB
放在
ComponentA
ng content

我试图做的类似于:

@ViewChild('componentB')componentBViewChild:componentB;
因此,我可以使用它的功能,如:

this.componentBViewChild.functionFoo();
问题是,我无法添加引用以将嵌套组件作为目标


欢迎提供任何帮助

使用
@ContentChild
而不是
@ViewChild
来引用投影内容
@ViewChild
仅查找直接在
组件的HTML模板中找到的元素

例如,给定具有以下HTML的
组件a


其用途如下:


您可以从
ComponentA
中引用
ComponentB
,如下所示:

@ContentChild(ComponentB)ComponentB:ComponentB;
可以找到文档