I want to pass an element reference to a directive. I know that the reference of the element on which the directive has been applied can be obtained by
private _elemRef: ElementRef
but I want to pass the reference to other element to the directive. Any help is appreciated.
Here's the demo code. I m using a ripple directive.
<ul #other>
<li ripple>Hello</li>
</ul>
directive.js
@Directive({
selector: '[ripple]'
})
export class RippleDirective {
constructor(private _elemRef: ElementRef) {
}
@HostListener('click', ['$event'])
public onClick(event: MouseEvent) {
// I wan't to refer the '#other' node here
}
}
[bracket]="func()"attribute. If you want to change that element, you could watch an event on your subcomponent. For other uses, specialized tags work well.