+ Start a Discussion
Pramodh KumarPramodh Kumar 

lightning event is not getting fired in init method

I having a problem invoking the lightning event in the init method...

Here is my code please look into it
<!--c:aeNotifier-->
<aura:component>
    <aura:registerEvent name="appEvent" type="c:aeEvent"/>
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>

    <h1>Simple Application Event Sample</h1>
    <p>
    </p>
</aura:component>

/* aeNotifierController.js */
{
    doInit : function(cmp, event) {
        // Get the application event by using the
        // e.<namespace>.<event> syntax
        var appEvent = $A.get("e.c:aeEvent");
        appEvent.setParams({
            "message" : "An application event fired me. " +
            "It all happened so fast. Now, I'm everywhere!" });
        appEvent.fire();
    }
}

<!--c:aeHandler-->
<aura:component>
    <aura:attribute name="messageFromEvent" type="String"/>
    <aura:attribute name="numEvents" type="Integer" default="0"/>

    <aura:handler event="c:aeEvent" action="{!c.handleApplicationEvent}"/>

    <p>{!v.messageFromEvent}</p>
    <p>Number of events: {!v.numEvents}</p>
</aura:component>

/* aeHandlerController.js */
{
    handleApplicationEvent : function(cmp, event) {
        var message = event.getParam("message");

        // set the handler attributes based on event data
        console.log(message)
        cmp.set("v.messageFromEvent", message);
        var numEventsHandled = parseInt(cmp.get("v.numEvents")) + 1;
        cmp.set("v.numEvents", numEventsHandled);
    }
}

<aura:application >
    
    <c:aeNotifier/>
    <c:aeHandler/>
	
</aura:application>

Thanks,
​pRAMODH.