Skip to content

Instantly share code, notes, and snippets.

@karkranikhil
Forked from pozil/componentEvent.evt
Created June 27, 2021 06:52
Show Gist options
  • Select an option

  • Save karkranikhil/e47a4713b0c3884255b23e3232ec9181 to your computer and use it in GitHub Desktop.

Select an option

Save karkranikhil/e47a4713b0c3884255b23e3232ec9181 to your computer and use it in GitHub Desktop.

Revisions

  1. @pozil pozil revised this gist Mar 23, 2017. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions componentEvent.evt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    <aura:event type="COMPONENT">
    <aura:attribute name="param" type="String"/>
    </aura:event>
  2. @pozil pozil created this gist Mar 23, 2017.
    5 changes: 5 additions & 0 deletions componentEventReceiver.cmp
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    <aura:component>
    <aura:handler name="myComponentEvent" event="c:componentEvent" action="{!c.handleMyComponentEvent}"/>

    <c:componentEventSender/>
    </aura:component>
    6 changes: 6 additions & 0 deletions componentEventReceiverController.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    ({
    handleMyComponentEvent : function(component, event, helper) {
    var value = event.getParam("param");
    alert("Received component event with param = "+ value);
    }
    })
    5 changes: 5 additions & 0 deletions componentEventSender.cmp
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    <aura:component>
    <aura:registerEvent name="myComponentEvent" type="c:componentEvent"/>

    <lightning:button label="Fire component event" onclick="{! c.fireMyComponentEvent }" />
    </aura:component>
    7 changes: 7 additions & 0 deletions componentEventSenderController.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    ({
    fireMyComponentEvent : function(component, event, helper) {
    var myEvent = component.getEvent("myComponentEvent");
    myEvent.setParams({"param": "It works!"});
    myEvent.fire();
    }
    })