0

I spent the whole day trying to figure out why this event is not getting fired, i tried both component and application events but noting worked although the code is pretty simple.

here is my code :

Event: EVT01_deleteItems

    <aura:event type="COMPONENT" >
    <aura:attribute name="item" type="To_do_Items__c"/>
 </aura:event> 

Child component: CMP03_Item

<aura:component implements="flexipage:availableForAllPageTypes" access="global" controller="TestContactLevels">

<aura:attribute name="Item" type="To_do_Items__c" />
<aura:registerEvent name="deleteItem" type="c:EVT01_deleteItems" />

<article class="slds-card">
   <lightning:icon title="Supprimer la tache" iconName="utility:delete" size="xx-small" class="icon"
                        onclick="{!c.deleteItem}" />
</article>

Child component controller :

deleteItem : function(cmp, event, helper) {
    var itemToBeDeleted = cmp.get("v.Item");
    var deleteEvent = cmp.getEvent("deleteItem");
    deleteEvent.setParams({"item": itemToBeDeleted });
    deleteEvent.fire();

}

Parent component: CMP02_toDoListItems

<aura:component implements="flexipage:availableForAllPageTypes" access="global">
<aura:attribute name="itemsToDisplay" type="To_do_Items__c[]" />
<aura:handler name="deleteItem" type="c:EVT01_deleteItems" action="{!c.mDeleteItem}"  /> 
<aura:iteration items="{!v.itemsToDisplay}" var="item">
   <c:CMP03_Item Item="{!item}"/>
</aura:iteration>

Parent component controller:

    mDeleteItem: function(cmp,event,helper){
   // nothing here, just a console log 
    console.log("does it work ? ");
}

am i missing something here ?

1 Answer 1

2

In handler you have

<aura:handler name="deleteItem" type="c:EVT01_deleteItems" action="{!c.mDeleteItem}"  /> 

But type is incorrect, you must use: event

<aura:handler name="deleteItem" event="c:EVT01_deleteItems" action="{!c.mDeleteItem}"  /> 

Here you can see this in the official doc.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.