What is the correct way of getting reference to Parent Angular Component?

112 Views Asked by At

I try to get in the child component reference to its parent Angular component based on components tree. What is the correct way to do this? I have found out that injector.view is actually the reference I am looking for but this API is not documented.

NOTE: Why I need this. I am mixing Angular with a canvas rendering library. The child actually will treat the parent as AbstractComponent it does not care about the concrete class of its parent. Since I am building a parallel canvas display tree on top of the Angular's components tree and the child need to add it self into the parents canvas container.

I am trying to inject into ChildComponent reference to the ParentComponent.

Example:

@Component({selector: "ParentComponent",
template: '<ChildComponent></ChildComponent>'})
export class ParentComponent extends AbstractComponent
{
      constructor(){ super()}
}


@Component({selector: "ChildComponent",
template: '<h1>Child</h1>})
export class ChildComponent extends AbstractComponent
{
      constructor(){ super()}
}
0

There are 0 best solutions below