[SalesForce] can’t save event aura:handler for an event

Going the the lightning trailhead I'm at the challenge for camping list events. Everything is done in the CampingForm and all seems to work

In the form component

<aura:registerEvent name="addItem" type="c:addItemEvent"/>

the form controller validates and all works and calls this helper

createItem : function(component, citem) {
    var createEvent = component.getEvent("addItem");
    createEvent.setParams({"item":citem});
    createEvent.fire();
}

All seems to work fine
Now in the campinglist component I need to handle that event
When I add this and try to save it

<aura:handler name="addItem" type="c:addItemEvent" action="{!c.handleAddItem}" />

I get this error

'Failed to save undefined: aura:handler has invalid name attribute value: addItem'

Any ideas why it doesn't like this. I'm doing pretty much the exact same thing that works in the expense app so I am at a loss as to why I cannot save this.

Best Answer

Since the addItemEvent is an COMPONENT event. You need to give the name,event and it action attribute.

Looking at your code, changing the type to event would solve the issue.

<aura:handler name="addItem" event="c:addItemEvent" action="{!c.handleAddItem}" />