You need to sign in to do that
Don't have an account?
smita bhargava
application event issue
I am newbie to lightining component and trying to understand applicaiton events.
I am passing value from child component to parent compnent via application event.
Here's the code.
But in parentcomponent controller, the alert(evtattribute) is returning [object object]
so its not taking value in attribute mesg.
Please help me out.
smita
I am passing value from child component to parent compnent via application event.
Here's the code.
ApplicationCommunicationEvt --------------------------- <aura:event type="APPLICATION" description="Event template"> <aura:attribute name="mesg" type="string" description="Communication Between Multiple Components" access="global"/> </aura:event> ChildComponent.cmp ------------------- <aura:component implements="flexipage:availableForAllPageTypes" access="global"> <aura:registerEvent type="c:ApplicationCommunicationEvt" name="someName"/> <aura:attribute name="greeting" type="string"/> <lightning:input type="string" label="Enter Some Data Here" aura:id="inpData"/> <lightning:button label="Click Here To Fire The Application Event" onclick="{!c.FireApplicationEvent}" variant="brand"/> </aura:component> ChilcComponentController.js -------------------------- ({ FireApplicationEvent : function(component, event) { var message=component.find("inpData").get("v.value"); alert('message='+message); var appEvent=$A.get("e.etaPrime:ApplicationCommunicationEvt"); appEvent.setParams({"mesg":message}); appEvent.fire(); } }) ParentComponent.cmp -------------------- <aura:component implements="flexipage:availableForAllPageTypes" access="global"> <!--This component will have an handle(or handle) the event--> <aura:attribute name="receivedevent" type="string"/> <aura:handler event="c:ApplicationCommunicationEvt" action="{!c.HandleTheApplicationEvent}"/> <!--Now this attribute receivedevent will get the value from the attribute of event--> <div class="slds-m-around_xx-small"> <c:ChildComponent /> <div> <p>{!v.receivedevent}</p> </div> </div> </aura:component> ParentComponentController.js ----------------------------- ({ HandleTheApplicationEvent : function(component, event) { var evtattribute=event.getParams("mesg"); alert(evtattribute); var response="something is good"; if (evtattribute==='Hi') { response="Hello"; } alert('Now response='+response); component.set("v.receivedevent",response); } })My requirement is if attribute in event is Hi then it should show me output as Hello.
But in parentcomponent controller, the alert(evtattribute) is returning [object object]
so its not taking value in attribute mesg.
Please help me out.
smita
use ,
var evtattribute=event.getParam("mesg"); Instead of
var evtattribute=event.getParams("mesg");it should be getParam not getParams
Hope it will helps you, let us know if it helps you
thanks sfdcMonkey.com
All Answers
use ,
var evtattribute=event.getParam("mesg"); Instead of
var evtattribute=event.getParams("mesg");it should be getParam not getParams
Hope it will helps you, let us know if it helps you
thanks sfdcMonkey.com
I was struggling since the last one hour.