-
-
Save mhamzas/2a97a44f8cab0603c45c947994095f61 to your computer and use it in GitHub Desktop.
Lightning - Passing data down the component hierarchy via a method
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
({ | |
executeMyMethod : function (component, event, helper) { | |
var params = event.getParam('arguments'); | |
console.log('Param 1: '+ params.param1); | |
console.log('Param 2: '+ params.param2); | |
} | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
({ | |
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