How to access Elements in a Templates using TemplateRef in angular

1.3k Views Asked by At

Suppose I have an HTML structure like this

<ng-template #template1>
    <div>
        element one
    </div>
    <div>
        element two
    </div>
    <div>
        element three
    </div>
</ng-template>

now, Inside this template, I have three elements, How can I access each element when I get the reference of it using TemplateRef. I tried using this

@ViewChild('template1', { static: false, read: TemplateRef }) template: QueryList<ElementRef>

but I am not getting individual elements, How can I achieve this

0

There are 0 best solutions below