Newer Version Available

This content describes an older version of this product. View Latest

Using Events in Lightning Console Apps

The Lightning framework uses event-driven programming, which allows you to create handlers to respond to interface events as they occur. The Lightning Console JavaScript API provides several events specific to Lightning console apps.

Events are fired from JavaScript controller actions. Events can contain attributes that can be set before the event is fired and read when the event is handled. Each event that works with Lightning console apps returns attributes that can be read once the event is fired. See the reference section of this guide for a list of attributes returned by each event.

To use console events, set up a handler in your Lightning component. The following handler, for example, listens for the lightning:tabCreated event, and calls the onTabCreated function in the component’s controller when the event occurs.

Let’s look at a more fleshed out example. The following component uses the lightning:tabClosed event.

When a tab is closed, the event handler calls onTabClosed in the component’s controller, which logs the tabId of the closed tab.

You can use Lightning console events with the Workspace API and Utility Bar API to customize your users’ experience. You can, for example, give a tab focus when it’s refreshed, or notify the user with a modal dialogue when a tab is replaced.