user12050907
user12050907

Reputation:

Can we access data from a Grandchild component in Angular 8

I have a parent component say 'Data'. In that 'Data' component I have multiple child components say 'Datachild1', 'Datachild2'. All this children are sharing one single child component between them say 'DataGrandChild'. Now my requirement is I need to access that 'DataGrandChild' directly from 'Data'. Can I do that. Please note I am very new to Angular. Any help would be greatly appreciated.

Upvotes: 0

Views: 841

Answers (2)

Kisinga
Kisinga

Reputation: 1729

I would suggest that you use a service for this kind of component communication. There are other methods, but as seeing the number of components you have, services would work best in your case. Here's a good answer that demonstrates this.

Upvotes: 1

Ilija Iličić
Ilija Iličić

Reputation: 507

This is the best explanation for me here https://fireship.io/lessons/sharing-data-between-angular-components-four-methods/

There is a couple of ways to share data (via Input, via ViewChild, via Output() and EventEmitter) and the last one here is what you need - sharing data between unrelated components: with a Service.

I hope that will help!

Upvotes: 2

Related Questions