Skip to content

Instantly share code, notes, and snippets.

@Sunil02kumar
Created March 3, 2017 15:19
Show Gist options
  • Save Sunil02kumar/faffe86276315b2d90615857aaf3d844 to your computer and use it in GitHub Desktop.
Save Sunil02kumar/faffe86276315b2d90615857aaf3d844 to your computer and use it in GitHub Desktop.
<aura:event type="COMPONENT" description="Event template" >
<aura:attribute name="msg" type="String" access="GLOBAL"/>
</aura:event>
<aura:component >
<aura:attribute name="msgFromNotifier" type="String"/>
<!-- give same name as that of notifier registerEvent name attribute -->
<aura:handler name="newCarAccident" event="c:carAccident" action="{!c.handleNotification}"/>
<!-- Handler should contains notifier component-->
<c:carAccidentNotifier />
<div>message from Notifier : <b>{!v.msgFromNotifier}</b></div>
</aura:component>
({
handleNotification : function(component, event, helper){
var sentMessage= event.getParam("msg");
component.set("v.msgFromNotifier", sentMessage);
}
})
<aura:component >
<aura:registerEvent name="newCarAccident" type="c:carAccident"/>
<h1>Car Accident Example: Fire Event by Clicking on Button</h1>
<ui:button label="Accident Took Place" press="{!c.fireCarAccidentEvent }"/>
</aura:component>
({
fireCarAccidentEvent : function(component, event, helper) {
var accidentEvent = component.getEvent("newCarAccident");
accidentEvent.setParams({"msg":"there is car Accident. Send ambulance."});
accidentEvent.fire();
}
})
<aura:application extends="force:slds" >
<c:CarAccidentHandler/>
</aura:application>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment