Newer Version Available
aura:method
Use <aura:method> to
define a method as part of a component's API. This enables you to directly call a method
in a component’s client-side controller instead of firing and handling a component
event. Using <aura:method> simplifies the code
needed for a parent component to call a method on a child component that it
contains.
The <aura:method> tag has these system attributes.
Declaring Parameters
An <aura:method> can optionally include parameters. Use an <aura:attribute> tag within an <aura:method> to declare a parameter for the method. For example:
For more information, see the Returning a Value section below.
Creating a Handler Action
This handler action shows how to access the arguments passed to the method.
Retrieve the arguments using event.getParam('arguments'). It returns an object if there are arguments or an empty array if there are no arguments.
Returning a Value
aura:method executes synchronously.
- A synchronous method finishes executing before it returns. Use the return statement to return a value from synchronous JavaScript code. See Return Result for Synchronous Code.
- An asynchronous method may continue to execute after it returns. Use a callback to return a value from asynchronous JavaScript code. See Return Result for Asynchronous Code.