I am currently working on a directive which simply manipulates the dom elements.
I wanted to access to template variables of the element which is the host of the directive, but I was unable to do that, because the result is always undefined.
directive:
@Directive({
selector: '[sample-directive]'
})
export class SampleDirective implements AfterViewInit {
@ViewChild('queryMe') queryMe: ElementRef;
ngAfterViewInit(): void {
console.log(this.queryMe);
}
}
sampleComponent.template.html:
<div #queryMe></div>
usage:
<sample-component [sample-directive]></sample-component>
Is it possible to use template variables like that?