Communicate Between Two Salesforce Lightning Components Using Attributes

How to Communicate Between Two Salesforce Lightning Component Using Attributes?

How to communicate between two Lightning component using attributes ?

Communication between the two lightning components simply means the transfer of data from child component to parent component or from parent component to child component. Any lightning component cannot communicate directly with its parent component and vice-versa. Any component cannot control other component using standard javascript. Component communication has to be defined by the programmer.

Component communication can be done in two ways :

  1. Using Attributes or Methods to transfer data from parent to child component.
  2. Using Events for Data Transfer from child to parent component.


Here we will discuss component communication using attributes.

Snippet of code for passing parent attribute value to child attribute :

  1. Parent Component :
  2. <aura:component access="global">
    <aura:attribute name="parentAttribute" type="String" default='test'/>
    <c:ChildComponent childAttribute="{!v.parentAttribute}"/>

  3. Child Component :
    <aura:component access="global">
    <aura:attribute name="childAttribute" type="String"/>
    <table class="slds-table ">
    <div class="topSpacing">
    <label class="slds-form-element__label ">Name</label>
    <div class="width"> <ui:outputText class="slds-output" value="{!v.childAttribute}"></ui:outputText> </div>

  4. Lightning Application
    <aura:application extends="force:slds"><c:ParentComponent/> </aura:application>

    your component UI look like below screenshot. Here we are passing default value for parent component to the child component.



Leave a Reply


We're not around right now. But you can send us an email and we'll get back to you, asap.


About Us

Forcetalks is a Salesforce collaboration platform for coders & developers, geeks & nerds, consultants & business heads, admins & architects, managers & marketers and of course the business owners. A community where you can learn from, where you can contribute to. For you. For Salesforce. Read More...

Copyright 2018 Forcetalks. All Right Reserved.

Log in with your credentials


Forgot your details?