Skip to content

Instantly share code, notes, and snippets.

@pozil
Last active March 13, 2021 20:21
Show Gist options
  • Save pozil/05337d5a64af11a4ebe99c5f303b3ef2 to your computer and use it in GitHub Desktop.
Save pozil/05337d5a64af11a4ebe99c5f303b3ef2 to your computer and use it in GitHub Desktop.
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