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 ...

Get Angular 2 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.