unable to pass method reference in lightning component
you need to define method
attribute of type Aura.Action
in your child component and pass the {!c.methodName}
to your child component from the parent/container component.
myComp.cmp
<aura:component>
<aura:attribute name="method" type="Aura.Action" />
<button onclick="{!v.method}" type="button"> click me </button>
</aura:component>
main.cmp
<aura:component>
<c:myComp method="{!c.handlepress}" />
</aura:component>
maincontroller.js:
({
"handlepress" : function(cmp,event,helper) {
console.log('button click');
}
})
Apart from praveen's solution you can try this one if you have a registered event. If you want to call passed function from controller and helper then use following code:
Handler function can be assigned to registered event in the component.
Suppose in c:someComponent I have
<aura:registerEvent name="onSomeThing" type="c:someEvent"/>
then, I can write as follows-
<c:someComponent onSomeThing="{!c.handleSomeThing}" />