angular - @ContentChildren 和 ng-template 的问题
问题描述
我有一个示例,我试图在 wrapper directive中使用所有指令。ContentChildren
具体来说,我已经LookupContainerDirective
设置了一个包装元素。然后,在 wrapper 元素中,我有一些模板,并且模板本身也包含LookupdDirective
在其中。我正在尝试获取所有LookupdDirective
引用LookupContainerDirective
。
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);
}
我还准备了 stackblitz示例(检查控制台输出)。
我希望控制台输出对的所有引用,LookupdDirective
但它显示没有(_results: Array[0]
)。如果我不使用模板而是使用常规元素,则会找到引用 ( _results: Array[1]
)。
解决方案
推荐阅读
- c# - 如何在acumatica中添加线和分割线
- python - 根据多列值的条件,使用索引和广播一次覆盖多列中的值
- android - 打开颤振活动并从android native导航到路由名称
- oracle-nosql - Oracle NoSQL 是否提供允许为列生成系统时间戳的功能
- google-app-engine - 如何每天自动重启一个 GAE 应用引擎版本?
- java - 如何在不删除春季实体的情况下删除多对多关系中的引用?
- jenkins - 无法在 Tomcat 上启动 Jenkins
- c++ - 使用 cv::Filestorage 读/写 Eigen::Matrix
- google-people-api - 谷歌:联系人搜索[方法:people.searchDirectoryPeople]
- c# - 如何解决锁上死锁的 SqlException 通信缓冲资源