ViewChildren for ng template

I have an angular2 component for which the template looks like this:

<div>
    <div><ng-template #left></ng-template></div>
    <div><ng-template #right></ng-template></div>
</div>

      

I would like to get a reference to all the elements ng-template

using ViewChildren

, but I have no idea what type I need to pass between the brackets.

+1


source to share


1 answer


@ViewChildren(TemplateRef) templates: QueryList<TemplateRef>;

ngAfterViewInit() {
  console.log(this.templates.toArray());
}

      

or



@ViewChild('left') left:TemplateRef;
@ViewChild('right') right:TemplateRef;

ngAfterViewInit() {
  console.log(this.left, this.right);
}

      

+2


source