[英]Angular 6 @ContentChildren doesn't query extended component
i've got a question about the ContentChildren decorator. 我对ContentChildren装饰器有疑问。
I want to create a controller user interface for the desktop. 我想为桌面创建一个控制器用户界面。 I created some components to handle the controller input (so a example for, lets say the start page could be this):
我创建了一些组件来处理控制器输入(因此,以一个示例为例,起始页面可能是这样):
The ControllerContainerComponent template looks like this: ControllerContainerComponent模板如下所示:
<template #host></template> <ng-content></ng-content>
(The template is a optional choice to generate panels by a json template) (该模板是通过json模板生成面板的可选选项)
Now I want the ControllerContainerComponent to query its children that are instance of ControllerContainerComponent. 现在,我希望ControllerContainerComponent可以查询其作为ControllerContainerComponent实例的子级。 If i use ControllerContainerComponent as the selector in the @ComponentChildren decorator it returns a empty list after the content has been initialized.
如果我将ControllerContainerComponent用作@ComponentChildren装饰器中的选择器,则在初始化内容后它将返回一个空列表。
After that I tried to query the exact class (in this case the PanelComponent) and then got some results, but they wouldn't include components like DifPanelComponent 之后,我尝试查询确切的类(在本例中为PanelComponent),然后得到了一些结果,但是它们不包括DifPanelComponent之类的组件。
My question is: 我的问题是:
Is this a issue with angular or did I do something wrong? 这是角度问题吗,还是我做错了什么?
EDIT: 编辑:
I found a question on stackoverflow that is kind of similiar, but does not quite give the answer I was looking for and is not about the current version of angular: Angular 2 - Using @ContentChildren for filtering a component's content 我在stackoverflow上发现了一个类似的问题,但没有给出我一直在寻找的答案,也不是关于angular的当前版本的: Angular 2-使用@ContentChildren过滤组件的内容
2nd EDIT: 第二次编辑:
Here is a stackblitz that demonstrates my problem: https://stackblitz.com/edit/angular-vfmnd3 这是一个演示我的问题的堆栈闪电战: https ://stackblitz.com/edit/angular-vfmnd3
You may need to provide
it. 您可能需要
provide
它。 providers:[{provide: ControllerContainerComponent, useExisting:Panel}]
Then you'd be able to query it. providers:[{provide: ControllerContainerComponent, useExisting:Panel}]
然后您就可以对其进行查询。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.