I'm working on a web app project and I'm trying to use Angular, I get some problem with component communication. For example, how a parent component exchange data with child component, how to communicate between siblings components.
There are three ways: parent to child - sharing data via input. child to parent - sharing data via viewChild with AfterViewInit. child to parent - sharing data via output and EventEmitter.
By using any of the following methods we can connect 2 components. using services. parent component calling viewchild. parent interacting with child using a local variable.
If you are trying to communicate from a parent component to a child component, this is pretty clearly described using @Input and EventEmitters with @Output in the angular docs.
Angular 2 component interaction
As for communication across siblings, I posted an answer in a similar question that might help with the issue of sharing data across sibling components. Currently, i think the shared service method is the most efficient.
angular-2-sibling-component-communication
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With