Say, there's a relation between two components in Angular:
// Parent component: ParentComponent
// Child component: ChildComponent
// in ParentComponent template
<pp-child></pp-child>
------
export class ChildComponent implements OnInit {
constructor(
// wonder if there's something like:
// private parentRef: HostParentRef
) {}
ngOnInit() {
console.log(this.parentRef); // This would print ParentComponent
}
}
What I want to know is if there's a way to find out its parent component's type in ChildComponent
level. If there is, I would get ParentComponent
in this case.
Any insight would be appreciated!
Edit: I'm not talking about accessing parent's property or communicating between two. I'm just simply wondering about parent component's type of a component on runtime.