Events communicate data across components. Events can contain attributes with values set before the event is fired and read when the event is handled.
//Fire a component event var compEvent = cmp.getEvent("sampleComponentEvent"); compEvent.fire(); //Fire an application event var appEvent = $A.get("e.c:appEvent"); appEvent.fire();
To get the name of the event that’s fired:
event.getSource().getName();
To get an attribute that’s passed into an event:
event.getParam("value");
To get all attributes that are passed into an event:
event.getParams();
event.getParams() returns an object containing all event parameters.
To get the current phase of an event:
event.getPhase();
To get the component that fired the event:
event.getSource();
To retrieve an attribute on the component that fired the event:
event.getSource().get("v.myName");
To pause the fired event:
event.pause();
event.preventDefault();
For example, you can prevent a lightning:button component from submitting a form when it’s clicked.
To resume event handling for a paused event:
event.resume();
To set a value for an event parameter:
event.setParam("name", cmp.get("v.myName");
If the event has already been fired, setting a parameter value has no effect on the event.
To set values for parameters on an event:
event.setParams({ key : value });
If the event has already been fired, setting the parameter values has no effect on the event.
To prevent further propagation of an event:
event.stopPropagation();
You can stop event propagation in the capture or bubble phase only.