Activity Forums Salesforce® Discussions How to swap 2 different component views in Salesforce Lightning?

  • Ravi

    Member
    November 4, 2016 at 1:59 pm

    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:

    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.
  • Parul

    Member
    September 21, 2018 at 1:16 pm

    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

  • shariq

    Member
    September 21, 2018 at 1:32 pm

    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.

Popular Salesforce Blogs

Popular Salesforce Videos