I am doing trailhead task of handling event through client side controller in lightning components.I need to set phone number through one component and it should get display through another component. My value is setting an attribute of event but it is not getting to another component. Can anyone please suggest where I am getting wrong?Following is my code:-

----- Event------

<aura:event type="APPLICATION" >
    <aura:attribute name="phone" type="String"/>

-----Component that fires the event:-PhoneNumberInput.cmp---

<aura:component >
    <aura:registerEvent name="PhoneNumberEvent" type="c:PhoneNumberEvent"/>
    <ui:inputPhone aura:id="phone" label="phone"/>
    <ui:button label="Show Phone" press="{!c.showPhone}"/>

-----js controller of Component that fires the event:-PhoneNumberInput.js----

    showPhone : function(component, event, helper) {
        console.log("Inside input controller");
        var phone = component.find("phone").get("v.value");
            "phone" : phone

-----Component that displays the phone value:-PhoneNumberOutput.cmp---

<aura:component >
    <aura:attribute name="number" type="String" default="No Phone Number"/>
    <aura:handler event="c:PhoneNumberEvent" action="{!c.outputPhone}"/>
    <ui:outputText aura:id="phone" value="{!v.number}"/>

--------js controller of Component that displays the phone value:-PhoneNumberOutput.js------

    outputPhone : function(component, event, helper) {
        console.log("Inside Output Controller");
       var phone = event.getParams("phone");

In PhoneNumberOutputController.js change event.getParams("phone") to event.getParam("phone"). event.getParams() returns an object, so you could also use event.getParams().phone.

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.