How to get the child component value in parent component
SampleEvent.evt
--------------------
<aura:event type="component" description="This is my first Event">
<aura:attribute name="info" type="String"/>
</aura:event>
ChildComponent.cmp
------------------
<aura:component>
<aura:registerEvent name="SampleComponentEvent" type="c:SampleEvent"/>
<ui:button label="Showdata" press="{!c.childComponentMethod}"/>
</aura:component>
ChildComponentController
------------------------
({
childComponentMethod:function(component,event,helper){
var v1=component.getEvent("SampleComponentEvent");
v1.setParams({
"info":"Brahmanaidu"
});
v1.fire();
}
})
ParentComponent.cmp
--------------------------
<aura:component>
<aura:attribute name="eventmessage" type="String"/>
<aura:handler name="SampleComponentEvent" event="c:SampleEvent" action="{!c.parentComponentMethod}"/>
<c:ChildComponent/>
Value is {!v.eventmessage}
</aura:component>
ParentComponent controller
----------------------------------
({
parentComponentMethod:function(component,event,helper){
var getvalue=event.getParam("info");
component.set("v.eventmessage",getvalue+'sfdcscenarios.blogspot.com');
}
})
Lightning application
--------------------------
<aura:application extends="force:slds">
<c:ParentComponent/>
</aura:application>
It's so nice article thank you for sharing a valuable content. google cloud online course
ReplyDelete