Is there a way directly return a value from a controller function which is invoked through aura:method?
Example: I have a "super" component with the following markup
SuperComp.cmp:
<aura:component>
<aura:method name="getValue" action="{!c.onGetValue}" access="public" />
</aura:component>
SuperCompController.js:
onGetValue : function(component, event, helper)
{
return 100;
}
In the application I instantiate the component and I want to call the public method like this
MyApp.cmp:
<aura:application>
<aura:handler name="init" value="{!this}" action="{!c.onInit}" />
<c:SuperComp aura:id="myComp" />
</aura:application>
MyAppController.js:
onInit : function(component, event, helper)
{
console.log(component.find("myComp").getValue());
}
Unfortunately the console output is always undefined (checked that getValue is invoked). So how can I get the value returned from the aura:method?
A workaround would be changing the definition of aura:method by adding an attribute which accepts a javascript callback function and call the callback, but that makes it not so reusable at all.