I'm trying to get access to ng content with @ContentChild. To better understand @ContentChild I tried to implement a simple code example. I also did research such as here
CodePudding user response:
You're almost right... One thing: the ref
s right place is on top the children directly.
<app-parent>
<app-child #refChild></app-child>
</app-parent>
Then it's not more undefined:
For the other direction you can use Services, EventEmitter or the Host
decorator like this (it's the child constructor):
constructor(@Host() parent: ParentComponent) {
console.log("Here it is", parent)
}