Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular @ContentChildren和ng模板有问题_Angular_Typescript - Fatal编程技术网

Angular @ContentChildren和ng模板有问题

Angular @ContentChildren和ng模板有问题,angular,typescript,Angular,Typescript,我有一个例子,我试图使用包装器指令中的ContentChildren获取所有指令 具体来说,我在包装器元素上设置了LookupContainerDirective。然后,在包装器元素中,我有一些模板,模板本身有LookupdDirective。我正在尝试获取LookupContainerDirective中的所有LookupdDirective引用 app.component.html <div appLookupContainer> <!-- <div appLoo

我有一个例子,我试图使用包装器指令中的
ContentChildren
获取所有指令

具体来说,我在包装器元素上设置了
LookupContainerDirective
。然后,在包装器元素中,我有一些模板,模板本身有
LookupdDirective
。我正在尝试获取
LookupContainerDirective
中的所有
LookupdDirective
引用

app.component.html

<div appLookupContainer>
  <!-- <div appLookupd></div> -->
  <ng-container *ngTemplateOutlet="myTemp"></ng-container>
</div>  


<ng-template #myTemp>
  <div appLookupd></div>
</ng-template>

查找容器.directive.ts

@ContentChildren(LookupdDirective, { descendants: true })
private _lookupDirectives: QueryList<LookupdDirective>;

ngAfterContentInit() {
  console.log(this._lookupDirectives);
}
@ContentChildren(LookupdDirective,{后代:true})
private\u lookupdirections:QueryList;
ngAfterContentInit(){
console.log(this.\u lookupdirections);
}
我还准备了示例(检查控制台输出)

我希望控制台输出对
LookupdDirective
的所有引用,但它显示没有引用(
\u results:Array[0]
)。如果我不使用模板,而是使用常规元素,则会找到引用(
\u results:Array[1]
)。

对此有一个解释

一个建议性的解决办法是:


如前所述

在角度内容投影和查询中,它表示“内容原样” 在模板中编写“而不是在DOM中可见的内容” 似乎在期待


看看这里,很相似,我想谢谢,这解决了我的问题。。。尽管如此,我还是希望他们能以一种能让我的例子起作用的方式来实现它。。。