I am not able to understand Aura:method attribute and how it helps in making asynchronous callbacks.. I went through this Link but was not able to understand its working.. Will be great help if anyone can provide docs for aura:method component and function type attribute in aura!? Thanks


aura:method is called synchronously. The trick to an asynchronous return value is a callback, which is a Function:

<!-- c:auraMethod -->
<aura:component controller="SimpleServerSideController">
    <aura:method name="echo"
      description="Sample method with server-side call">
        <aura:attribute name="callback" type="Function" />

    <p>This component has an aura:method definition.</p>

A Function is a normal JavaScript type that is a function.

var logMessage = function(param) { console.log(param); }

In this example, logMessage is a Function. You can do a number of interesting things with it:

logMessage("This is a message.")
logMessage.call(null, "This is another message.");
logMessage.apply(null, ["This is yet another message."]);

Also, if you want to formalize a reference with parameters:

var sayHelloWorld = logMessage.bind(null, "Hello World");
sayHelloWorld(); // outputs "Hello World"

The two links I included should answer any further questions you have.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.