Note: This release is in preview. Features described here don’t become generally available until the latest general availability date that Salesforce announces for this release. Before then, and where features are noted as beta, pilot, or developer preview, we can’t guarantee general availability within any particular time frame or at all. Make your purchase decisions only on the basis of generally available products and features.
Fire Component Events
Register an Event
A component registers that it may fire an event by using <aura:registerEvent> in its markup. For example:
1<aura:registerEvent name="sampleComponentEvent" type="c:compEvent"/>We’ll see how the value of the name attribute is used for firing and handling events.
Fire an Event
To get a reference to a component event in JavaScript, use cmp.getEvent("evtName") where evtName matches the name attribute in <aura:registerEvent>.
Use fire() to fire the event from an instance of a component. For example, in an action function in a client-side controller:
1var compEvent = cmp.getEvent("sampleComponentEvent");
2// Optional: set some data for the event (also known as event shape)
3// A parameter’s name must match the name attribute
4// of one of the event’s <aura:attribute> tags
5// compEvent.setParams({"myParam" : myValue });
6compEvent.fire();