Firing an application event

You can fire an event from the controller or helper file by using the following code snippet:

var appEvent = $A.get("e.c:appEvent");// Optional: set some data for the event (also known as event shape)// A parameter's name must match the name attribute// of one of the event's <aura:attribute> tags//appEvent.setParam({ "message" : myValue });appEvent.fire();

Notice that we have used a global $A variable, and we obtain the instance of the application event using the type of the application. Also, use setParam (for only one parameter) or setParams() (for multiple parameters) to provide the ability to set the event attributes.

Get Learning Salesforce Lightning Application Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.