Methods in Lightning components do not return a value, also came to the same outcome as yourself.
However, I did learn to use and love component events with dynamic event handlers. What you can do from the calling component is fire a component event from within the component you wish to call the method on currently and attach a dynamic event handler for the component finishes processing.
So for example, you can fire an event from where you want to fire the method now like so:
otherComponent.getEvent('provide').fire();
Then also attach a dynamic event handler to listen for a response:
otherComponent.addHandler('responseEvent', component, 'c.handlingControllerAction');
The approach has the benefit of decoupling your components and if you need your other component to do asynchronous work then you can as also the response event would be fired asynchronously. It also allows multiple components to listen out for this event and also react accordingly.
Find more information on the Salesforce help:
https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/js_cb_dynamic_handler.htm
Hope this helps!
I am not sure you have configured correctly the components.
In your child component (lets call it childComponent) you need to define the aura:method
and give it an action
with a javascript method name, also I think Function
type of attribute is not supported, but anyway I would make this a general object and pass it a json object so it can change easily as you please:
<aura:method name="methodOnChild" action="executeFromParent">
<aura:attribute name="data" type="Object" />
</aura:method>
After that, to execute the method - in your parent component you need to identify your childComponent so you can give it an aura:id
when you are instantiating it, for example (you can do that in other ways):
<c:childComponent aura:id="childComponentId" />
Then in your parent component controller - you need to create the params to return, and then get the childComponent and execute the method like this:
var data = {
givenId: component.get("v.givenId"),
field2: component.get("v.field2"),
field3: component.get("v.field3"),
field4: component.get("v.field4"),
field5: component.get("v.field5"),
picklistValues: component.get("v.picklistValues")
};
var childComponent = component.find("childComponentId");
childComponent.methodOnChild(data);
Finally on your childComponent you need to have the javascript method on your controller (the aura:method
will call this method):
executeFromParent : function (component, event, helper) {
var data = event.getParam('data');
// now data contains your json - do whatever you want with it
}
Best Answer
You are not returning result from the ChildComp controller method. Use below after closing of if statement
Check Salesforce Doc https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/js_cmp_methods_sync.htm