我有一个angular2组件,模板看起来像这样:
<div>
<div><ng-template #left></ng-template></div>
<div><ng-template #right></ng-template></div>
</div>
Run Code Online (Sandbox Code Playgroud)
我希望能够检索所有ng-template元素的引用,ViewChildren但我不知道我需要在括号之间传递的类型.
Gün*_*uer 12
@ViewChildren(TemplateRef) templates: QueryList<TemplateRef>;
ngAfterViewInit() {
console.log(this.templates.toArray());
}
Run Code Online (Sandbox Code Playgroud)
要么
@ViewChild('left') left:TemplateRef;
@ViewChild('right') right:TemplateRef;
ngAfterViewInit() {
console.log(this.left, this.right);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11088 次 |
| 最近记录: |