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
Ravi Sankar 12Ravi Sankar 12 

using Aura:method to call other component and passing params

Hello All,

I am trying to call other component using aura:method, but getting some errors. I appreciate if you can help.
Apex Controller


public class TestingIntegrationErrorHandling {
    @AuraEnabled
    public static object sampleCallout(){
        system.debug('entered apex');
       
        return object;
    }
}

The controller is working perfect
 
Parent Component:

<aura:component implements="flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId" access="global" controller="CDI_TestingIntegrationErrorHandling" >
	<aura:attribute name="messageLog" type="Object__C" />
    <c:CDI_TestComponentParent aura:id="child"/>
    <lightning:button label="CallErrorHandlingComp" onclick="{! c.callChildMethod }" />
</aura:component>

Controller:
callChildMethod : function(component, event, helper) {
       console.log('calling child method');
       
        var action = component.get("c.sampleCallout"); 
        action.setCallback(this, function(result){
            var messageLog = result.getReturnValue();
            console.log('---messageLog-- ' + messageLog);
            component.set("v.messageLog", messageLog);
            
        });
        var childCmp = component.find("MessagePanel");
        var retnMsg = childCmp.executeMyMethod(messageLog);
        consolo.log('executing child');
        
        $A.enqueueAction(action);      
        
	}
 
Child component:
<aura:component access="global">	
    <aura:method name="executeMyMethod" action="{!c.executeMyMethod}">
         <aura:attribute name="messageLog" type="MessageLog__c" />
    </aura:method>	
</aura:component>

Controller:
executeMyMethod : function (component, event, helper) {
        var params = event.getParam('arguments');
        if (params) {
            var param1 = params.MessageLog__c;
			console.log('param1  ' + param1);
            component.set('v.messageLog',params.MessageLog__c);
            
        }
    }

Thank you for your help
Best Answer chosen by Ravi Sankar 12
Deepali KulshresthaDeepali Kulshrestha
Hi Ravi,

As per your requirement ,see the below code to call one component into another and pass parameter to it:

<aura:component implements="flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId" access="global" controller="CDI_TestingIntegrationErrorHandling" >

    <aura:attribute name="messageLog" type="Object__C" />

    <c:YourChildComponent childattribute="youvalueTOPass"/>

    <lightning:button label="CallErrorHandlingComp" onclick="{! c.callChildMethod }" />

</aura:component>


YourChildComponent:

<aura:component  implements="flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId" access="global" access="global"> 
   <aura:atttribute name="youvalueTOPass" type="String"/>
    <aura:method name="executeMyMethod" action="{!c.executeMyMethod}">

         <aura:attribute name="messageLog" type="MessageLog__c" />

    </aura:method>   

</aura:component>


I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Deepali Kulshrestha
www.kdeepali.com

All Answers

Parteek Goyal 3Parteek Goyal 3
Hi Ravi,

Could you please help with error screenshot..

Thanks
Parteek
Ravi Sankar 12Ravi Sankar 12
Hello Prateek,
Apologoes for that.
Below is the screenshot. User-added image
Deepali KulshresthaDeepali Kulshrestha
Hi Ravi,

As per your requirement ,see the below code to call one component into another and pass parameter to it:

<aura:component implements="flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId" access="global" controller="CDI_TestingIntegrationErrorHandling" >

    <aura:attribute name="messageLog" type="Object__C" />

    <c:YourChildComponent childattribute="youvalueTOPass"/>

    <lightning:button label="CallErrorHandlingComp" onclick="{! c.callChildMethod }" />

</aura:component>


YourChildComponent:

<aura:component  implements="flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId" access="global" access="global"> 
   <aura:atttribute name="youvalueTOPass" type="String"/>
    <aura:method name="executeMyMethod" action="{!c.executeMyMethod}">

         <aura:attribute name="messageLog" type="MessageLog__c" />

    </aura:method>   

</aura:component>


I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Deepali Kulshrestha
www.kdeepali.com
This was selected as the best answer