You need to sign in to do that
Don't have an account?
Simon234
Get/set an attribute trough Lightning Event
I can't get the attribute trough Lightning Event. By clicking on the button "Get msg" I get `undefined`:
ceEvent.evt:
ceEvent.evt:
<aura:event type="COMPONENT"> <aura:attribute name="message" type="String" default="111"/> </aura:event>ceNotifier.cmp:
<aura:component> <aura:attribute name="msg" type="String"/> <aura:registerEvent name="cmpEvent" type="c:ceEvent"/> <aura:handler name="cmpEvent" event="c:ceEvent" action="{!c.handleComponentEvent}"/> <lightning:button label="Get msg" onclick="{!c.getMsg}" /> <p>{!v.msg}</p> </aura:component>ceNotifierController.js:
({ handleComponentEvent : function(cmp, event) { var cmpEvent = cmp.getEvent("cmpEvent"); var message = cmpEvent.getParam("message"); cmp.set("v.msg", message); alert(message); }, getMsg : function(cmp, event) { var cmpEvent = cmp.getEvent("cmpEvent"); var message = cmpEvent.getParam("message"); alert(message); }, })ceHandler.cmp:
<aura:component> <aura:attribute name="messageFromEvent" type="String"/> <aura:handler name="cmpEvent" event="c:ceEvent" action="{!c.handleComponentEvent}"/> <aura:registerEvent name="cmpEvent" type="c:ceEvent"/> <lightning:button label="Send msg" onclick="{!c.fireComponentEvent}" /> <c:ceNotifier /> </aura:component>ceHandlerController.js:
({ handleComponentEvent : function(cmp, event) { var message = event.getParam("message"); cmp.set("v.messageFromEvent", message); alert(message); }, fireComponentEvent : function(cmp, event) { var cmpEvent = cmp.getEvent("cmpEvent"); cmpEvent.setParams({"message" : "Here we go"}); cmpEvent.fire(); alert(cmpEvent.getParam("message")); } })ceApp.app:
<aura:application > <c:ceHandler/> </aura:application>What am I doing wrong? How do i get an attribute?