Activity Forums Salesforce® Discussions How to get parent Salesforce lightning component's attribute in child component?

  • Kumar

    Member
    January 18, 2017 at 1:14 pm

    Hi Tanu,

    You have two options.

    1. Fire an event that your containing component can listen for and act upon.
    2. Pass in a reference to the attribute to the child component.

    <c:childComponent myValue="{!v.B}"/>

    When the childComponent updates myValue, v.B will also update.

    Hope this helps.

  • shariq

    Member
    September 13, 2018 at 8:33 am

    Hi,

    Component communication can be done in two ways :

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

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

    <aura:component access="global"/>

    <aura:attribute name="parentAttribute" type="String" default='test'/>

    <c:ChildComponent childAttribute="{!v.parentAttribute}"/> //here 'ChildAttribute' is an attribute in child component.

    </aura:component>

    Hope this helps!

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos