Child Component Code Snippet : AuraMethodChildCMP.cmp
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" > <aura:method name="auraMethod" action="{!c.getAurMethodProperties}"> <aura:attribute name="firstName" type="String" default="Fazurulla"></aura:attribute> <aura:attribute name="lastName" type="String" default="Ganganapalli"></aura:attribute> </aura:method> </aura:component>
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" > <aura:method name="auraMethod" action="{!c.getAurMethodProperties}"> <aura:attribute name="firstName" type="String" default="Fazurulla"></aura:attribute> <aura:attribute name="lastName" type="String" default="Ganganapalli"></aura:attribute> </aura:method> </aura:component>
JS:
({
getAurMethodProperties : function(component,event,helper){
alert(event.getParam('arguments').firstName);
alert(event.getParam('arguments').lastName);
}
})
Parent Component Code Snippet : AuraMethodParentCMP.cmp
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
<div class="slds-m-around_xx-large">
<c:AuraMethodChildCMP aura:id="childCmp"/>
<lightning:button variant="brand" label="Submit" onclick="{!c.callAuraMethod}" />
</div>
</aura:component>
JS:
({
callAuraMethod : function(component, event, helper) {
var childComponent = component.find("childCmp").auraMethod();
}
})
APP: AuraMethodAPP.app
<aura:application extends="force:slds">
<c:AuraMethodParentCMP></c:AuraMethodParentCMP>
</aura:application>
No comments:
Post a Comment