Skip to content

Instantly share code, notes, and snippets.

@meajinkya
Created October 1, 2018 09:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save meajinkya/e3fb41161fa73718aedd141cb2f7a100 to your computer and use it in GitHub Desktop.
Save meajinkya/e3fb41161fa73718aedd141cb2f7a100 to your computer and use it in GitHub Desktop.
Parent/Child Message Passing using Attributes
<!-- Parent component "parent.cmp" -->
<aura:component>
<aura:attribute name="myAttr" type="String" default="world" />
<c:child myAttrChild="{!v.myAttr}">
</aura:component>
<!-- Child component "child.cmp" -->
<aura:component>
<aura:attribute name="myAttrChild" type="String"/>
<lightning:input name="input1" label="Enter some text" value="{!myAttrChild}" />
</aura:component>
/**
* parentController.js
*/
({
fooMethod : function(component, event, helper) {
var myAttrChild = component.get("v.myAttr");
console.log("myAttrChild: ", myAttrChild);
}
})
If user enters some value in input1 in child component and then fooMethod is called,
myAttr in parent will have the same value as myAttrChild.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment