function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Mohammed Sheriff 1Mohammed Sheriff 1 

how to pass data from one lightning page to another

How can I pass data from one lightning component and to another lightning component. Please help ?

Thanks in advance
 
Best Answer chosen by Mohammed Sheriff 1
Ajay K DubediAjay K Dubedi
Hi Mohammed,

You can use the below code.

Component Name: First_Component  

<aura:component >
    <aura:attribute name="Data" type="String" default="abcd"/>
    <c:Second_Component showData="{!v.Data}"/>
</aura:component>

Component Name: Second_Component 

<aura:component >
    <aura:attribute name="showData" type="String"/>
    {!v.showData}
</aura:component>

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Ajay Dubedi
www.ajaydubedi.com

All Answers

Valentin F.Valentin F.
Hi Mohammed,

It depends if they are parent-child components or different components.
You should use the events :
Component event is for passing data between parent-child components.
Application event is for passing data between different components.

Here you can find the documentation : 
https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/events_intro.htm

Have a good day !
Valentin
Ajay K DubediAjay K Dubedi
Hi Mohammed,

You can use the below code.

Component Name: First_Component  

<aura:component >
    <aura:attribute name="Data" type="String" default="abcd"/>
    <c:Second_Component showData="{!v.Data}"/>
</aura:component>

Component Name: Second_Component 

<aura:component >
    <aura:attribute name="showData" type="String"/>
    {!v.showData}
</aura:component>

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Ajay Dubedi
www.ajaydubedi.com
This was selected as the best answer