function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Lukesh KarmoreLukesh Karmore 

i have an issue with aura:method

i have a little problem , i wrote an aura:method  in child component and while writing parent component controller what should i write  aura:method name or its action name...
hope u understand what i mean...thank u
my code is..
child component:
<aura:component controller="AccountDetails" >
 <aura:method name="sampleMethod" action="{!c.doAction}" 
  description="method shows Account Details"> 
  <aura:attribute name="param1" type="String" default="account"/> 
    <aura:attribute name="param2" type="Object" /> 
</aura:method>
 </aura:component>

parent component:


    callAuraMethod : function(component, event, helper) {
        var Childcmp = component.find("c.child");
        Childcmp.sampleMethod(function(result){
         component.set("v.AccountList",result)                 
                 });
      }
}) 
 

simply my issue is in parent component controller .....  Childcmp.sampleMethod(function(result)
                                    OR    Childcmp.doAction(function(result)

thank you
AnudeepAnudeep (Salesforce Developers) 
Simply call the function and pass parameter value in parent component. See the example below from this blog post

ChildCmp.cmp
 
<!--ChildCmp.cmp-->
<aura:component >
    <aura:method name="GetMessageFromChildMethod" action="{!c.getMessage}"
                 access="public">
        <aura:attribute name="Name" type="String" default="Amit"/>
    </aura:method>
</aura:component>

ChildCmpController.js
 
({
    getMessage : function(component, event) {
        var params = event.getParam('arguments');
        if (params) {
            var param1 = params.Name;
            return "##### Hello "+param1+" From Child Component #####";
        }
        return "";
    }
})

ParentCmp.cmp
 
<!--ParentCmp.cmp-->
<aura:component >
    <aura:attribute name="message" type="String"
                    default="------ Hello From Parent -----"/>
    <c:ChildCmp aura:id="childComponent"/>
  
    <div class="slds-m-around_xx-large">
        <lightning:button variant="brand" label="Call Aura Method"
                          onclick="{!c.callAuraMethod}" />
        <BR></BR> <BR></BR>
        <p>{!v.message}</p>
    </div>
</aura:component>

ParentCmpController.js
 
({
     callAuraMethod : function(component, event, helper) {
            var childCmp = component.find("childComponent");
            var retnMsg = childCmp.GetMessageFromChildMethod('Amit');
            component.set("v.message", retnMsg);
     }
})