With a structural directive, how would I get a hold of the (native) element the directive is on? With a normal directive, the ElementRef has it's nativeElement pointing to it - eg:
<input type="text" example>
@Directive({
selector: '[example]'
})
export class ExampleDirective {
constructor( private el: ElementRef) {}
ngAfterViewInit() {
console.log(this.el.nativeElement); // the input
}
}
But with a structural directive, it points to the template comment - eg.
<input type="text" *example>
@Directive({
selector: '[example]'
})
export class ExampleDirective {
constructor(
private el: ElementRef,
private view: ViewContainerRef,
private template: TemplateRef<any>
) {}
ngAfterViewInit() {
this.view.createEmbeddedView(this.template);
console.log(this.el.nativeElement); // template bindings comment
// how to find the input itself?
}
}
I've tried using various combinations of ViewContainerRef, TemplateRef, @ContentChild, @ViewChild - just don't seem to be able to find the input element itself...