Another Salesforce blog!!!

Salesforce, Apex

understanding how the component event fired


Lets create the component event first and called it “StudentSelectedEvent”:

<aura:event type="COMPONENT" description="Selected Student" >
    <aura:attribute name="contactId" type="Id" ></aura:attribute> 
</aura:event>

The name attribute in must match the name attribute in the tag in the component that fires the event.

in the above component event the type of event is “COMPONENT” and we have one attribute which is “contactId” and type of it is “Id”

to event handle or capture the handler:

 <aura:handler name="onStudentSelected" 
                  event="c:StudentSelectedEvent" 
                  action="{!c.onStudentSelected}" />
 onStudentSelected: function(component,event,helper) {
        
        var contactId = event.getParam('contactId');
        component.set('v.selectedContactId',contactId);
        helper.broadcastStudentSelected(component);
    }
 onStudentSelected: function(component,event,helper) {
        
        var contactId = event.getParam('contactId');
        component.set('v.selectedContactId',contactId);
        helper.broadcastStudentSelected(component);
    }

–Helper

   broadcastStudentSelected : function(component) {
           alert('broadcastStudentSelected');
        alert('clicked on tile to know more about?')
        var appEvent = $A.get("e.c:AwinstructorsStudentSelectedEvent");
        appEvent.setParams({
            				 courseDeliveryId : component.get('v.selectedCourseDeliveryId'),
                             contactId: component.get('v.selectedContactId')
        				   });
        
        //alert('Event Name: ' + appEvent.getName());
        //alert('Event Type: ' + appEvent.getType());
        appEvent.fire();
        
    },

Leave a Reply

Your email address will not be published.

*