It should be available throught DI
@Directive({
selector: '[myDirective]',
})
export class MyDirective {
constructor(private otherDirective: MyOtherDirective) {}
}
It there's no such directive on the same element then make sure you use @Optional
decorator.
Alternatively, you can pass it as an @Input
my-other.directive.ts
@Directive({
selector: '[myOtherDirective]',
exportAs: 'myOtherDirective'
})
export class MyOtherDirective {}
template.html
<div myDirective [otherDirective]="other" #other="myOtherDirective"
myOtherDirective>Hello World</div>
my.directive.ts
@Directive({
selector: '[myDirective]',
})
export class MyDirective {
@Input() otherDirective: MyOtherDirective;
}