我有一个angular2组件,其模板如下所示:
<div>
<div><ng-template #left></ng-template></div>
<div><ng-template #right></ng-template></div>
</div>我希望能够使用ViewChildren检索对所有ng-template元素的引用,但我不知道需要在括号之间传递的类型。
发布于 2017-03-03 16:04:41
@ViewChildren(TemplateRef) templates: QueryList<TemplateRef>;
ngAfterViewInit() {
console.log(this.templates.toArray());
}或
@ViewChild('left') left:TemplateRef;
@ViewChild('right') right:TemplateRef;
ngAfterViewInit() {
console.log(this.left, this.right);
}https://stackoverflow.com/questions/42567236
复制相似问题