You need to sign in to do that
Don't have an account?
Vikash 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
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
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. Component:
UserInput.cmp which would accept two input values from the user and sum it.
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: 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:
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: 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:-
Thank You,
http://www.nubeselite.com/
Development | Training | Consulting
Please mark this as solution if your problem is resolved.
({
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.