In my angular application, the app component is as follows:
<table>
<tr appA="Hello" *ngFor="let row of rows">
<ng-container *ngTemplateOutlet="tdTemplate">
</ng-container>
</tr>
<ng-template #tdTemplate>
<td appB>
</td>
</ng-template>
</table>
There are 2 directives, ADirective and BDirective. In BDirective I need to get a referenece to the ADirective that was placed on its parent <tr>
@Directive({
selector: '[appB]'
})
export class BDirective {
constructor(private a: ADirective) { }
}
Since the <td> is below the <tr> in the actual DOM, I expected the Dependency Injection to be able to provide it. But since the DI travels up the View hierarchy, not the actual DOM Hierarchy I get a NullInjectorError instead.
Is there any way for the BDirective to get a hold of the ADirective, assuming that the structure of the app.component.html cannot be changed?