Im using the aura:method in my lightning component, but I want to get the data from the apex class, so that i'm tying to pass the value from my component to the aura:method but i don't know how to pass the value for asynchronous call, Please help me..


method definition:

aura:method component QuoteLineItemHelper_Cmp

<aura:method name="echo" description="Sample method with server-side call">
        <aura:attribute name="quoteId" type="String"/>
        <aura:attribute name="callback" type="Function" />

Called from component:

<c:QuoteLineItemHelper_Cmp aura:id="child" />

 var recordId  = component.get("v.recordId");
var childCmp = component.find("child");
     childCmp.echo(recordId,function(result) {
                console.log("callback for aura:method was executed");
                console.log("result: " + result);

is this way of passing the parameter to the aura:mehtod is correct, it is not working for me..

  • Are you trying to call an <aura:method> with a parameter that you are getting from your Apex controller, or are you trying to return data from an <aura:method> that is coming from the Apex controller? The latter is what your link is covering. – David Reed Apr 12 '18 at 14:07
  • Yes.. Im passing the record id from my component to <aura:method> and i wrote a function in <aura:method> to get record from controller and then the <aura:method> will return those values back to the component. i don't know how to pass the parameter value from component to asynchronous call aura:method – Parthiban Apr 12 '18 at 14:11
  • The article that you linked shows how to implement this exact structure. Can you edit your question to be more specific about what aspect you are struggling with? – David Reed Apr 12 '18 at 14:13
  • In that link they showed how to call the function alone in the aura:method but how to pass the parameter.. from component to aura:method var childCmp = component.find("child"); // call the aura:method in the child component childCmp.echo(function(result) { console.log("callback for aura:method was executed"); console.log("result: " + result); }); – Parthiban Apr 12 '18 at 14:16
  • What does "not working" mean? You need to be specific about where and how it fails, whether you receive any errors, and what the JavaScript console shows. Please read through How to Ask; it is really helpful if you can start with this information so we don't play 20 questions. – David Reed Apr 12 '18 at 14:49

You can pass an arbitrary number of parameters to an <aura:method>, whether or not that method ultimately calls an asynchronous function.

Here's an example from the <aura:method> documentation:

<aura:method name="sampleMethod" action="{!c.doAction}" 
  description="Sample method with parameters"> 
    <aura:attribute name="param1" type="String" default="parameter 1"/> 
    <aura:attribute name="param2" type="Object" /> 

You access these in JavaScript by doing

    var params = event.getParam('arguments');
    if (params) {
        var param1 = params.param1;
        // get more params the same way.

It doesn't matter if one of the params is a callback function to receive asynchronous results because fundamentally all <aura:method> parameters are passed the same way.


You can send params to Asynchronous Aura Method just like Synchronous. And your syntax is absolutely correct. Please check if your Attribute has any value or try hardcoding param's value and log it in your child component.

Out of curiosity I tried this and its working.

Child Cmp:

<aura:component >
    <aura:method name="childmethod" action="{!c.readParams}"> 
        <aura:attribute name="param1" type="Account"/>
        <aura:attribute name="param2" type="String"/>
        <aura:attribute name="callback" type="Function"/>

Child Cntlr

readParams : function(component, event, helper) {
        var params = event.getParam('arguments');
        console.log('params from auramethod-->',JSON.stringify(params));

Parent Cmp:

<aura:component implements="flexipage:availableForAllPageTypes">
    <c:childcomponent aura:id="myuniquechildID"/>
    <lightning:button variant="brand" label="Send Params to Child" onclick="{!c.sendParams}" />

Parent Cntlr

    sendParams: function (component, event, helper) {
        const childCmpReference = component.find('myuniquechildID');        
        childCmpReference.childmethod('sampleParam1','sampleParam2', function(result){
            /*do any other actions with result*/

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.