Configuring mutual parent-child awareness with ViewChild and forwardRef
Depending on your application's separation of concerns, it might make sense for a child component in your application to reference a parent, and at the same time, for the parent to reference the child. There are two similar implementations that allow you to accomplish this: using ViewChild
and ContentChild
. This recipe will discuss them both.
Note
The code, links, and a live example of this are available at http://ngcookbook.herokuapp.com/1315/.
Getting ready
Begin with the recipe setup shown in Referencing a parent component from a child component. Your objective is to add the ability to enable and disable the like button from the parent component.
How to do it...
The initial setup only gives the child access to the parent, which is only half of what you need. The other half is to give the parent access to the child.
Getting a reference to FeedbackComponent
that you see in the ArticleComponent
template view can be done in...