You need to sign in to do that
Don't have an account?

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.
Thank you for your help
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
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
Could you please help with error screenshot..
Thanks
Parteek
Apologoes for that.
Below is the screenshot.
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