In Angular2 it's possible to inject an parent or even ancestor (eg. grandparent) component to child by simply using the following syntax:
export class Grandchild {
constructor( @Optional() @Host() @Inject(forwardRef(() => Ancestor)) ancestor)
}
However, that seems to work only for ancestor-grandchild relations that are defined in a single template, like following:
<!-- App component template -->
<ancestor>
<foobar>
<grandchild></grandchild> <!-- injection works -->
</foobar>
</ancestor>
If, instead our templates would be like as follows, the injection will not work:
<!-- App component template -->
<ancestor>
<foobar></foobar>
</ancestor>
<!-- Foobar component template -->
<grandchild></grandchild> <!-- injection doesn't work -->
I have made a plunker for this: http://plnkr.co/edit/D9iSokONIAFAS8G1NTd1