Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Lightning - Passing data down the component hierarchy via a method
<aura:component >
<aura:method name="myMethod" action="{!c.executeMyMethod}">
<aura:attribute name="param1" type="String"/>
<aura:attribute name="param2" type="String"/>
</aura:method>
</aura:component>
({
executeMyMethod : function (component, event, helper) {
var params = event.getParam('arguments');
console.log('Param 1: '+ params.param1);
console.log('Param 2: '+ params.param2);
}
})
<aura:component >
<aura:attribute name="parentAttribute1" type="String" default="A"/>
<aura:attribute name="parentAttribute2" type="String" default="B"/>
<c:childComponent aura:id="child"/>
<lightning:button label="Call child method" onclick="{! c.callChildMethod }" />
</aura:component>
({
callChildMethod : function(component, event, helper) {
var attribute1 = component.get('v.parentAttribute1');
var attribute2 = component.get('v.parentAttribute2');
var childComponent = component.find('child');
childComponent.myMethod(attribute1, attribute2);
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.