Handling component events

To handle a component event, declare an aura:handler in the handling component. Note that you will need to specify the exact name of the handler, equal to the name used when registering the event:

<aura:handler name="sampleComponentEvent" event="c:compEvent" action="{!c.handleComponentEvent}"/>

Note that a component can also self-handle an event raised by itself. In that case, both the register and handler tags are present on the component. The syntax is as follows:

<aura:registerEvent name="sampleComponentEvent" type="c:compEvent"/><aura:handler name="sampleComponentEvent" event="c:compEvent" action="{!c.handleSampleEvent}"/>

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.