2

Is it possible for a lightning component to make a call to the method in another component by using the name of its aura:method dynamically? Or can it only be hardcoded?

e.g

Child component:

<aura:method name="myMethod" action="{!c.myMethod}"/>

Parent component hard coded:

var childCmp = component.find('childCmp');
childCmp.myMethod();

I want do to something like this:

var methodName = 'myMethod' ;
var childCmp = component.find('childCmp');
childCmp.methodName();

1 Answer 1

6

Sure, you can dynamically call aura method accessing a function through the bracket notation []:

var methodName = 'myMethod' ;
var childCmp = component.find('childCmp');
childCmp[methodName]();

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .