I am trying to pass data from one child component to the parent component using custom events; I don't have the expected results on the parent component
<!--Event File : DisplayCount.evt-->
<aura:event type="COMPONENT" description="Event template">
<aura:attribute name = "count" type = "Integer" default ="0"/>
</aura:event>
<!--Child Component - Firing the event-->
<aura:component controller="FetchOpportunities" implements="force:appHostable" >
<aura:attribute name = "columns" type = "List"/>
<aura:attribute name = "data" type = "Opportunity[]"/>
<aura:attribute name = "count" type = "Integer" default = "2"/>
<aura:registerEvent name="sampleComponentEvent" type="c:DisplayCount"/>
<aura:handler name="init" value="{! this }" action="{!c.onLoad}"/>
<div>
Total number of opportunities : {!v.count}
<!-- <lightning:button label ="Click here" onclick="{!c.firecomponentevent}"/> -->
<ui:button label = "Click here Now" press ="{!c.firecomponentevent}"/>
<lightning:card footer="Card Footer" title="All Opportunities">
<lightning:datatable
keyField="id"
data="{! v.data }"
columns="{! v.columns }"
hideCheckboxColumn="true"/>
</lightning:card>
</div>
</aura:component>
<!--//Child JS file-->
({
onLoad : function(component, event, helper) {
console.log("Fetchdata");
component.set('v.columns', [
{label: 'Opportunity name', fieldName: 'Name', type: 'text'},
{label: 'Stage name', fieldName: 'StageName', type: 'text'},
{label: 'Close date', fieldName: 'closeDate', type: 'date'}
]);
var action = component.get("c.getOpportunity");
action.setCallback(this, function(response){
var state = response.getState();
console.log("The value of state"- response.getState());
if(state === "SUCCESS"){
component.set("v.data",response.getReturnValue());
component.set("v.count",response.getReturnValue().length);
}
});
$A.enqueueAction(action);
},
firecomponentevent: function(component, event, helper){
console.log("entered firecomponent");
var childcompEvent = component.getEvent("sampleComponentEvent");
childcompEvent.setParams({
"count" : 56
});
childcompEvent.fire();
}
})
<!--//Parent Component - Event handler-->
({
onLoad : function(component, event, helper) {
console.log("Fetchdata");
component.set('v.columns', [
{label: 'Opportunity name', fieldName: 'Name', type: 'text'},
{label: 'Stage name', fieldName: 'StageName', type: 'text'},
{label: 'Close date', fieldName: 'closeDate', type: 'date'}
]);
var action = component.get("c.getOpportunity");
action.setCallback(this, function(response){
var state = response.getState();
console.log("The value of state"- response.getState());
if(state === "SUCCESS"){
component.set("v.data",response.getReturnValue());
component.set("v.count",response.getReturnValue().length);
}
});
$A.enqueueAction(action);
},
firecomponentevent: function(component, event, helper){
console.log("entered firecomponent");
var childcompEvent = component.getEvent("sampleComponentEvent");
childcompEvent.setParams({
"count" : 56
});
childcompEvent.fire();
}
})
<!--//Parent JS file-->
({
handleSubmit : function(component, event, helper) {
// Submit buttom will automatically create the record
// component.find("opp").submit();
},
handleSuccess : function(component, event, helper) {
component.set("v.reloadForm", false);
component.set("v.reloadForm", true);
},
handlecomponentevent : function(component, event, helper) {
console.log("came to parent component")
var count = event.getParam("count");
component.set("v.count",count);
}
})