Communication with grandchildren


#1

What is the best choice to communicate with grandchildren?

For example.

I have a HomePage with footer buttons. Inside HomePage I have a component X. Inside the component X I have a component Y, which is a form product.

I wanna to action a footer button from HomePage to method of Component Y, but with that instance.
Injectable create a new component (dont works).

Would be awesome if could be:

(home.html)
<my-component-products #products>
button click=“products.product.add()”

(my-component-products.html)
– list of product –
<my-component-product-form #product>

(my-component-product-form.ts)
add() {
console.log(“I’m being fired from the homepage”);
}

Do you understand me ? I would like to speak with the instances of my grandchildren!

Why I cannot use products.product.add() ??


#2

I think you’re going about this backwards. Instead of trying to force activity downward, use a shared service that maintains the data model. Add things there from wherever needed, and subscribe to change in the model where those need to be represented.


#4

Thank you!! I resolved the problem with the data in the service.