You need to sign in to do that
Don't have an account?
bretondev
Lightnin Event fired but not received
I am sending a Lightning Event from a component which is supposed to be received by another component.
The event is fired when clicking on a button.
I did some debugging : the event does get fired but the receiving method is not triggered.
Event :
Notifier COmponent :
Receiving component controller :
The event is fired when clicking on a button.
I did some debugging : the event does get fired but the receiving method is not triggered.
Event :
<aura:event type="APPLICATION" description="Event template"> <aura:attribute name="boatTypeId" type="String" /> </aura:event>
Notifier COmponent :
<aura:component controller="BoatSearch"> <aura:registerEvent name="formSubmit" type="c:FormSubmit"/> <lightning:button onclick="{!c.onFormSubmit}" /> </aura:component>Notifier component controller :
({ onFormSubmit: function (component) { var compEvent = component.getEvent("formSubmit"); compEvent.fire(); } })Receiving component:
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes" controller="BoatSearchResults" > <aura:handler name="formSubmit" event="c:FormSubmit" action="{!c.search}"/> </aura:component>
Receiving component controller :
({ search : function(component, event) { //var boatTypeId = event.getParam("message"); helper.onSearch(component); } })The event is fired but I do not reach search() method, why?
Between the application and component event, there are syntax differences when you fire or handle them.
1) Fire Application Events: Use $A.get("e.myNamespace:myAppEvent") in JavaScript to get an instance of the myAppEvent event in the myNamespacenamespace.
var appEvent = $A.get("e.c:appEvent");
appEvent.setParams({ "myParam" : myValue });
appEvent.fire();
https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/events_application_fire.htm
2) Handling Application Events: Use <aura:handler> in the markup of the handler component.
For example:
<aura:handler event="c:appEvent" action="{!c.handleApplicationEvent}"/>
The handler for an application event won’t work if you set the name attribute in <aura:handler>.
IMPORTANT: Use the name attribute only when you’re handling component events.
https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/events_application_handling.htm
3) Here is the great post for: Lightning Inter-Component Communication Patterns
https://developer.salesforce.com/blogs/developer-relations/2017/04/lightning-inter-component-communication-patterns.html
All Answers
Between the application and component event, there are syntax differences when you fire or handle them.
1) Fire Application Events: Use $A.get("e.myNamespace:myAppEvent") in JavaScript to get an instance of the myAppEvent event in the myNamespacenamespace.
var appEvent = $A.get("e.c:appEvent");
appEvent.setParams({ "myParam" : myValue });
appEvent.fire();
https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/events_application_fire.htm
2) Handling Application Events: Use <aura:handler> in the markup of the handler component.
For example:
<aura:handler event="c:appEvent" action="{!c.handleApplicationEvent}"/>
The handler for an application event won’t work if you set the name attribute in <aura:handler>.
IMPORTANT: Use the name attribute only when you’re handling component events.
https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/events_application_handling.htm
3) Here is the great post for: Lightning Inter-Component Communication Patterns
https://developer.salesforce.com/blogs/developer-relations/2017/04/lightning-inter-component-communication-patterns.html
As suggested by Alain in detail , you should be able to catch the vent.
As the event you are using is Application TYPE hence key is to make sure that
The handler for an application event won’t work if you set the name attribute in <aura:handler>.
If you follow stpes above, it should work.
Regards
Girish P