Activity › Forums › Salesforce® Discussions › How to swap 2 different component views in Salesforce Lightning?
Tagged: Lightning Component Framework, Lightning View, Salesforce Lightning, Salesforce Lightning Components
-
How to swap 2 different component views in Salesforce Lightning?
Posted by Tanu on November 2, 2016 at 2:25 PMHi All,
How to swap 2 different component views in Lightning?
shariq replied 7 years, 7 months ago 4 Members · 3 Replies -
3 Replies
-
You can do this using lightning event.Lightning event is best way communicate between two components.
You need to follow these steps for these type of scenario:
- Create a main component which will be use as container for two components.
- Let suppose you want to swap from component A to component B.First create view for component A in main component.
- When you want to swap from component A to B fire an event from A that will be handled bu main component.
- Main component will destroy component A and will create Component B.
- [adinserter block='9']
-
Hi,
Lightning event is best way communicate between two components.So for this,Please use lightning event.
Below are the steps for these type of scenario:
1.Create a main component which will be use as container for two components.
2.Let suppose you want to swap from component A to component B.First create view for component A in main component.
3.When you want to swap from component A to B fire an event from A that will be handled bu main component.
4.Main component will destroy component A and will create Component B.Thanks
-
Hi,
You can use the standard methods for lightning to swap components. $A.createComponent() method to create another component from one component and component.destroy () method to destroy the new created component.
$A.createComponent(
“c:AddAgreementComponent”, // creating a component
{
“productWrapper”: productWrapObj // setting the attribute of a component.
},
function(newComponent, status, errorMessage){
if (status === “SUCCESS”) {
var body = component.get(“v.body”);
body.push(newComponent);
component.set(“v.body”, body);
}
}
);Thanks
Log In to reply.