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
Vikash Kumar MandalVikash Kumar Mandal 

How to pass parameter from one component to another page's component in lightning

Hi All,

I want to pass attribute as parameter from one lightning component to another page's lighting component in community. But I am unable to pass it.

Please help me in this.

Thanks!
Vikash
sai venu madhav  reddy ALLAsai venu madhav reddy ALLA
Hi Vikash,
Use  Lightning events to pass the values from one component to another component.
Example:-UserInput and DisplayResult.’ UserInput’ component accepts two user input values and we need to add these values and display the result in the ‘DisplayResult.cmp’. How the UserInput.cmp will pass the calculated value to the DisplayResult.cmp? We have to use a lightning event in this case which will allow UserInput.cmp to fire the event, that will be caught by the event handlers of DisplayResult.cmp.
Lightning Event: First create an event named “Result.evt”. Since the user input component has a value to be passed to the DisplayResult component. So the event needs an attribute to store the value.
<aura:event type="APPLICATION">
<aura: attribute name="Pass_Result" type="String" />
</aura:event>
 Component:
UserInput.cmp which would accept two input values from the user and sum it.
User-added image
Look at the above component, UserInput has registered the event “Result” using the tag in the component. This is a declaration that the component states to notify that  “UserInput” component will fire the “Result” event at some point of time.
Now create the client-side controller for UserInput.cmp.
UserInputController.js:
({
Add : function(component, event, helper) {
var get_num1 = component.find(“Input1”).get(“v.value”);
var get_num2 = component.find(“Input2”).get(“v.value”);
var res = parseInt(num1) + parseInt(num2);
var evt = $A.get(“e.c:Result”);
evt.setParams({ “Pass_Result”: res});
evt.fire();
}
In the above client-side controller of UserInput, we get the user inputs and converted it to integer data type, adding the two values. Then the final result is passed to the “Result” event and fired.
Now, we need to define the DisplayResult, which will display the result.
DisplayResult.cmp:
User-added image
In DisplayResult tag used to register the application event which was created.
When the event is fired, the getValueFromApplicationEvent action in the client-side controller of the handler component is invoked.
Now create the controller for DisplayResult.cmp
DisplayResultController.js:
({
getValueFromApplicationEvent : function(cmp, event) {
var ShowResultValue = event.getParam(“Show_Result”);
// set the handler attributes based on event data
cmp.set(“v.Get_Result”, ShowResultValue);
}
})
The controller retrieves data from the Event named “Result” and set the retrieve data in the DisplayResult.cmp attribute name “Get_Result“.
Now create a Salesforce Lightning Application named “MyApp” to access these components in Salesforce:-
User-added image
  Thank You,
        http://www.nubeselite.com/
        Development | Training | Consulting
        Please mark this as solution if your problem is resolved.
Ghanshyam Singh 5Ghanshyam Singh 5
DisplayResultController.js:
({
getValueFromApplicationEvent : function(cmp, event) {
var ShowResultValue = event.getParam(“Show_Result”);
// set the handler attributes based on event data
cmp.set(“v.Get_Result”, ShowResultValue);
}
})
Note:- Instead of "Show_Result"  we can use "Pass_result" Because we  have field value into Pass_result.