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.
aura:method
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:
1<aura:method name="sampleMethod" action="{!c.doAction}"
2 description="Sample method with parameters">
3 <aura:attribute name="param1" type="String" default="parameter 1"/>
4 <aura:attribute name="param2" type="Object" />
5</aura:method>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.
1({
2 doAction : function(cmp, event) {
3 var params = event.getParam('arguments');
4 if (params) {
5 var param1 = params.param1;
6 // add your code here
7 }
8 }
9})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.