You need to sign in to do that
Don't have an account?
sheila srivatsav
application event concept
My understanding of application event is if two components not related to each then we can use applicaiton event to pass data.
Please correct me if wrong.
I have done a code but I am unable to pass data.
I checked using debugger but value is not comoing into the child attribute from the parent.
Please let me know where I go wrong.
thanks
sheila S
Please correct me if wrong.
I have done a code but I am unable to pass data.
ApplicationEvent.vt <aura:event type="APPLICATION" description="Event template"> <aura:attribute name="message" type="string" access="public"/> </aura:event> ParentComponent.cmp <aura:component implements="flexipage:availableForAllPageTypes" access="global" > <aura:attribute name="someattr" type="string" default="I am GOD" access="private"/> <aura:registerEvent name="handleApplicationEvent" type="c.ApplicationEvent"/> <lightning:button name="clickMe" label="ClickMe" onclick="{!c.HandleApplicationEvent}"/> </aura:component> PrentComponentController.js ({ HandleApplicationEvent : function(component, event, helper) { debugger; var applnEvent=$A.get("e.c:ApplicationEvent"); var val=component.get("v.someattr"); console.log(val); applnEvent.setParams({"message" : val}); applnEvent.fire(); } }) ChildComponent.cmp <aura:component > <aura:attribute name="receivedvaluefromparent" type="string" access="private"/> <aura:handler event="c:ApplicationEvent" action="{!c.HandleApplicationEvent}"/> <c:ParentComponent/> Inside the child component : {!v.receivedvaluefromparent} </aura:component> ChildComponent.js ({ HandelApplicationEvent : function(component, event, helper) { debugger; var evtMessage=event.getParam("message"); console.log(evtMessage); component.set("v.receivedvaluefromparent",evtMessage.ToString()); } }) MainApp.app <aura:application > <c:ParentComponent/> </aura:application>
I checked using debugger but value is not comoing into the child attribute from the parent.
Please let me know where I go wrong.
thanks
sheila S
You can get a better explanation at the below link.
http://www.sudipta-deb.in/2016/03/salesforce-lightning-component_27.html
Component Vs Application events.
http://www.sfdcstuff.com/2017/09/application-events-vs-component-events.html
Please mark it best if it helps you. Thanks.
MainApp.app
<aura:application >
<c:ParentComponent/>
<c:ChildComponent/>
</aura:application>
I made a small change. I removed the parentcomponent from the the childcomponent markup.
Then I tried but value in message attribute of event is not comoing into the parent component attribute.
also I called <c:ChildComponent/> in aura:application but it throws error.