Hope this will help you out in your requirements.
- Create the event.
Event: setAttributeEvent
<aura:event type="COMPONENT">
<aura:attribute name="attributeValue" type="String"/>
</aura:event>
- Register the event in child component.
Component: ChildComponent
<aura:component>
<aura:registerEvent name="setAttribute" type="c:setAttributeEvent"/>
<ui:inputText aura:id="val"/>
<ui:button label="setParentAttributeValue" action="{!c.setValue}"/>
</aura:component>
- Fire the event through the child component controller.
Controller: ChildComponentController
({
setValue: function(component, event, helper)
{
var inputfieldValue = component.find("val").get("v.value");
var setEvent = component.getEvent("setAttribute");
setEvent.setParams({"attributeValue":inputfieldValue});
setEvent.fire();
}
})
- Handle the event in parent component fired from child component.
Component: ParentComp
<aura:component>
<aura:handler name="setAttribute" event="c:setAttributeEvent" action="{!c.setAttributeValue}"/>
<aura:attribute name="B" type="String"/>
<c:ChildComponent/>
</aura:component>
- Perform the necessary action.
Controller: ParentCompController
({
setAttributeValue: function(component, event, helper)
{
var eventValue= event.getParam("attributeValue");
component.set("v.B", eventValue);
}
})
PS: Name used in RegisterEvent should match with Handler name, else event will not be handled.