Same Type of Communication in Lightning Component exists in Lightning Web Component also. Following are the mechanisms to communicate between Lightning Web Components.
Direct Call Lightning Web Component with certain attributes – Remember this communication is in one direction, not by bi-directional or back & forth. In Lightning Component (in Aura framework), the communication can be bi-directional using bound expressions, that’s why it was very hard to maintain and performance was not good during using of unnecessarily/accidentally bi-directional communication. This is a primary difference between Lightning Component & Lightning Web component with respect to Communication mechanism.
Using Method – We can call the method with parameters of the Lightning Web Component from other Lightning Web Component. The flow of this communication is from Parent to Child Component.
Using Custom Event – We can call the Parent Component from Child Component with some properties. The flow of this communication is from Child to Parent Component.
Using Publish-Subscriber model – This is just like Application Event communication like in Lightning Component (in Aura Framework).
Using Slot – This is the HTML markup communication by which we can send the HTML markup from Parent Component to Child Component where <slot> tag is defined.
First of all, we need to understand the Owner, Container & Containment Hierarchy for Communication Purpose.
Okay, let’s start. We will discuss all the above communication process one by one.
5,439 total views, 6 views today