3

I have a child component inside my parent component as below:

<aura:iteration items="{!v.articolo.items}" var="item">
    <c:RigaTabellaItemsKit item="{!item}" PicklistStatoKit_SelVal="{!v.PicklistStatoKit_SelVal}" aura:id="item_in_kit"/>
</aura:iteration>

During some operation inside the Helper of the parent component, I should call a function defined inside the child component.

Helper (Parent):

var pesi_value = component.get("v.pesi");
var articoloKit = component.get("v.articolo");
var itemsInKit = articoloKit.items;
var value1 = 2.0;

for (var i = 0; i < pesi_value.length; i++){
    itemsInKit[i].voce.Prezzo_totale__c = value1 * pesi_value[i];
    //here I should call a function inside the child component.
}

Assume that the function which I want to call is as described inside the Helper of the child as below:

calcolaRicarico : function(component, event, helper) {
    helper.calcolaRicarico(component, event);
}

How could I do that?

1 Answer 1

10

you can call using aura:method by using aura:id

<c:RigaTabellaItemsKit  aura:id="item_in_kit"/>

Helper (Parent):

cmp.find("item_in_kit").calcolaRicarico();

In child:

<aura:method name="calcolaRicarico" action="{!c.calcolaRicarico}" />
7
  • I added the line you mentioned to the child. and in my parent (helper) I called component.find("item_in_kit").calcolaRicarico(); But it gave me error that this function does not exist.
    – ReshaD
    Commented Jan 17, 2017 at 15:47
  • Did you handled <aura:method>in child component .As you mentioned you want to call child helper method... you need to call helper method from child controller.
    – vignesh
    Commented Jan 17, 2017 at 16:02
  • Yes the method is already defined if you meant defining it by handling
    – ReshaD
    Commented Jan 17, 2017 at 16:06
  • Nope.I meant to define a method in child component. for parent component to call a method on a child component ..
    – vignesh
    Commented Jan 17, 2017 at 16:19
  • Yep, it is defined already.
    – ReshaD
    Commented Jan 17, 2017 at 16:47

You must log in to answer this question.

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