+ Start a Discussion
Henry MoserHenry Moser 

Updating sum in parent component from child components

I have a parent component that iterates through a list of objects that are displayed in child components. Each child component has an input for an integer (default 0), and the parent component has an attribute that needs to be displayed as the sum of all child components' inputs.

What's the method of dynamically displaying the sum from the parent on change to any of the child components' input?
Raj VakatiRaj Vakati
You can able to do it by using the events ..The effective mechanism by which two components can work is by using Events .Lightning framework works on Event driven paradigm .

Ravi Dutt SharmaRavi Dutt Sharma
Make use of component events.

1) Create an event of type "COMPONENT"

2) In the child component, create a change handler on the integer attribute.
<aura:handler name="change" value="{!v.count}" action="{!c.handleCountChange}"/>

3) In your controller, in the handleCountChange, get the event you created in step 1, set the count attribute as a parameter and fire the event.

4) In the parent component, declare a handler for the event created in step 1. Also keep an attribute to roll up the count. Increment this count when you handle the event.

Hope this helps.