Skip to main content
1 of 2
KaLi
  • 1.5k
  • 3
  • 24
  • 38

I had the same requirement to self refresh a component. The details are discussed below briefly. The approach is based on the idea suggested by Fabien above.

Steps to Self Refresh a Component

SCENARIO :: The scenario is to create a Contact record via LDS. I have a Lightning Card with the Contact Input Fields. Once the Contact is saved I wanted to refresh the Component to show blank input Fields ready to create next Contact record.

Step 01 :: Create an Event

<aura:event type="COMPONENT" description="Self Refresh" />

Step 02 :: Register Fire and Handle the event by calling appropriate JS method

<!-- Register and handle the Refresh Event to refresh the current component -->
<aura:registerEvent name="selfRefreshEvt" type="c:compSelfRefresh" />

<!-- Now handle the selfRefreshEvt by calling createCntCreateTempl which is the same method called on init to initialize a Contact Obj  -->
<aura:handler name="selfRefreshEvt" event="c:compSelfRefresh" action="{!c.createCntCreateTempl}" />

Step 03 :: Fire the Event

// Fire selfRefreshComp Evt (start)
// Get the component event by using the name value from aura:registerEvent
var selfRefreshEvent = component.getEvent("selfRefreshEvt");              
selfRefreshEvent.fire();      
// Fire selfRefreshComp Evt (end)
KaLi
  • 1.5k
  • 3
  • 24
  • 38