You need to sign in to do that
Don't have an account?
brahmanaidu
unable to get the data on clicking of a button(Component Event)
ChildComponent
--------------
<aura:component >
<ui:button label="click me" press="{!c.hanldeClick}"/>
<aura:registerEvent name="componentevent" type="c:SimpleComponentEvent"/>
</aura:component>
SimpleComponentEvent.evt
------------------------
<aura:event type="component" description="component" >
<aura:attribute name="message" type="string"/>
</aura:event>
controller
------------
({
hanldeClick : function(component, event, helper) {
var v1=component.get("componentevent");
v1.setParams({
"message":'Welcome to sfdcscenarios.blogspot.com'
});
v1.fire();
}
})
ParentComponent
---------------
<aura:component >
<aura:attribute name="EventMessage" type="String"/>
<aura:handler name="componentevent" event="c:SimpleComponentEvent" action="{!c.hanldeParent}"/>
<c:ChildComponent/>
{!v.EventMessage}
</aura:component>
Controller
-----------
({
handleParent: function(component, event, helper) {
var message = event.getParam("message");
cmp.set("v.EventMessage", message + 'brahmanaidu');
}
})
--------------
<aura:component >
<ui:button label="click me" press="{!c.hanldeClick}"/>
<aura:registerEvent name="componentevent" type="c:SimpleComponentEvent"/>
</aura:component>
SimpleComponentEvent.evt
------------------------
<aura:event type="component" description="component" >
<aura:attribute name="message" type="string"/>
</aura:event>
controller
------------
({
hanldeClick : function(component, event, helper) {
var v1=component.get("componentevent");
v1.setParams({
"message":'Welcome to sfdcscenarios.blogspot.com'
});
v1.fire();
}
})
ParentComponent
---------------
<aura:component >
<aura:attribute name="EventMessage" type="String"/>
<aura:handler name="componentevent" event="c:SimpleComponentEvent" action="{!c.hanldeParent}"/>
<c:ChildComponent/>
{!v.EventMessage}
</aura:component>
Controller
-----------
({
handleParent: function(component, event, helper) {
var message = event.getParam("message");
cmp.set("v.EventMessage", message + 'brahmanaidu');
}
})
1. var v1 = component.getEvent("componentevent"); [it should be getEvent() not
get()]2. second your parent component handler action name and controller method names are not matching they should be same handleParent
thanks hope it will helps you
All Answers
ChildComponent
ParnetCMP
1. var v1 = component.getEvent("componentevent"); [it should be getEvent() not
get()]2. second your parent component handler action name and controller method names are not matching they should be same handleParent
thanks hope it will helps you