I just started lightning component development. When i tried to fire an event from the page its not firing. Can somebody suggest me where i missed it. Here is my code. I just like to know where i missed it. I tried in all the possible ways but no luck. Can somebody tell me where i am missing. Thanks in advance.
Component:
<aura:component >
<aura:attribute name="acc" type="Account" default="{sobjectType:'Account',
name:'',
description:''}"/>
<aura:registerEvent name="InsertAccount" type="c:DMLEvent" description="Fire an DML event on saving the record"/>
<lightning:layout >
<lightning:layoutItem >
<lightning:input type="text" label="Name" value="{!v.acc.Name}" name="nameOfAcc"/>
<lightning:input type="text" label="Description" value="{!v.acc.Description}" name="des"/>
<lightning:button type="button" label="Save Account" onclick="{!c.saveAccount}" />
</lightning:layoutItem>
</lightning:layout>
</aura:component>
Component Controller:
({
saveAccount : function(component, event, helper) {
console.log('########');
var initializeDMLInfo =$A.get('e.c:DMLEvent');
initializeDMLInfo.setParams({'sObjectInfo':component.get('v.acc')});
initializeDMLInfo.fire();
}
})
Event:
<aura:event type="APPLICATION" description="Event template" >
<aura:attribute name="sObjectInfo" type="Sobject" />
</aura:event>
Event Handler Component:
<aura:component >
<aura:handler name="handleEvent" event="c:DMLEvent" action="{!c.doDML}" />
</aura:component>
Event Handler Components Controller:
({
doDML : function(component, event, helper) {
console.log('#########'+event.getSource());
}
})