Expand my Community achievements bar.

SOLVED

AEM 6.5, SPA, Angular 9 - How do I subscribe to a parent container component from a child component?

Avatar

Level 2

AEM 6.5, SPA, Angular 9

In the editor and published page via Typescript, I'd like to subscribe to a parent container component from a child component.  If I drag a parent container component on the editor page and then drag a child component so it is inside of the parent container, how can the child get a reference to it's closest parent so it can subscribe to parent changes?

When a component is dragged onto the editor page, are there certain Angular-monitored events that are triggered and would help with a solution?

Two use cases I'm trying to solve:

  1. The parent container has a background color property that is also the background color of any child component.  The child component needs to know what its closest parent's background color is so it can use the appropriate text color.
  2. To dynamically build a backend data structure, the child needs to know the ID of its closest parent component.

 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hey @dpkhmhs 

 

This is thr AEP community. Post your query in the AEM community thread to get a faster response.

 

Here's the link: https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/ct-p/adobe-experience-mana...

 

Cheers,

Abhinav

View solution in original post

1 Reply

Avatar

Correct answer by
Community Advisor

Hey @dpkhmhs 

 

This is thr AEP community. Post your query in the AEM community thread to get a faster response.

 

Here's the link: https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/ct-p/adobe-experience-mana...

 

Cheers,

Abhinav