Skip to content

Instantly share code, notes, and snippets.

@iamsonal
Last active June 29, 2017 12:04
Show Gist options
  • Save iamsonal/a07a9dcdd2a282726a5347d17a3dd082 to your computer and use it in GitHub Desktop.
Save iamsonal/a07a9dcdd2a282726a5347d17a3dd082 to your computer and use it in GitHub Desktop.
<!--c:eventsNotifier-->
<aura:component>
<aura:attribute name="parentName" type="String"/>
<aura:registerEvent name="componentEventFired" type="c:compEvent"/>
<aura:registerEvent name="appEvent" type="c:appEvent"/>
<div>
<h3>This is {!v.parentName}'s eventsNotifier.cmp instance</h3>
<p>
<lightning:button label="Click here to fire a component event" onclick="{!c.fireComponentEvent}" />
</p>
<p>
<lightning:button label="Click here to fire an application event" onclick="{!c.fireApplicationEvent}" />
</p>
</div>
</aura:component>
/* eventsNotifierController.js */
{
fireComponentEvent : function(cmp, event) {
var parentName = cmp.get("v.parentName");
// Look up event by name, not by type
var compEvents = cmp.getEvent("componentEventFired");
compEvents.setParams({ "context" : parentName });
compEvents.fire();
},
fireApplicationEvent : function(cmp, event) {
var parentName = cmp.get("v.parentName");
// note different syntax for getting application event
var appEvent = $A.get("e.c:appEvent");
appEvent.setParams({ "context" : parentName });
appEvent.fire();
}
}
/* eventsNotifier.css */
.cEventsNotifier {
display: block;
margin: 10px;
padding: 10px;
border: 1px solid black;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment