You need to sign in to do that
Don't have an account?
Create an event that passes phone information between two components
Hi All,
After attempting lighting component module.I am facing with the following problem.
https://developer.salesforce.com/trailhead/force_com_dev_intermediate/lightning_components/lightning_components_events_handle
1-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.send}"/>
</aura:component>
2-PhoneNumberOutput.cmp
<aura:component >
<aura:attribute name="phone" type="String" default="No Phone Number"/>
<ui:outputText aura:id="phone" value="{!v.phone}"/>
<aura:handler event="c:PhoneNumberEvent" action="{!c.answer}"/>
</aura:component>
3-PhoneNumberEvent.evt
<aura:event type="APPLICATION" description="Event template">
<aura:attribute name="phone" type="String"/>
</aura:event>
4-PhoneNumberInputController.js
({
setphone:function (component, event,helper){
var phone=component.find("phone").get("v.value");
$A.get("e.c:PhoneNumberEvent").set Params({
phone:phone
}).fire(),
}
})
5-PhoneNumber.app
<aura:application >
<c:PhoneNumberInput />
<c:PhoneNumberOutput />
</aura:application>
Thanks
Prashant
Hi Chandra Sekhar CH N V
After using your code ,the error was same
Challenge not yet complete... here's what's wrong:
The 'PhoneNumberOutput' client-side controller is not getting the phone param
Thanks For the replay ..Ya i am using your code in PhoneNumberOutput.cmp but the error was same .
PhoneNumberInputHelper.js). I am pasting my code snippet which worked for me.
Seems U r not capturing the phone param in PhoneNumberOutput Controller.
({
answer : function(component, event, helper) {
var text = event.getParam("phone");
component.set("v.number", phone);
}
})
Add this in ur PhoneNumberOutputController.js - This would capture the phone param. Thanks!!
Uncaught error in $A.run() : Unable to find 'send' on 'compound://c.PhoneNumberInput'.
any help would be greatly appreciated. Thank you.
Input Controller:
Phone Number Output Component:
Phone Number Input Component:
Phone Number Event :
Try this............
Thanks
Nirmallya Ghosh
- Phone Number Output Component:
<aura:component ><aura:attribute name="number" type="string" default="No Phone Number"/>
<aura:handler event="c:PhoneNumberEvent" action="{!c.getphone}"/>
<c:PhoneNumberInput />
<ui:outputText aura:id="phone" value="{!v.number}"/>
</aura:component>
2. Output Controller :
({
getphone : function(component, event, helper) {
var text = event.getParam("phone");
// alert(text);
component.set("v.number", text);
}
})
3 . Phone Number Input Component:
<aura:component>
<aura:registerEvent name="PhoneNumberEvent" type="c:PhoneNumberEvent"/>
<ui:inputPhone aura:id="phone" label="phone" />
<ui:button label="Show Phone" press="{!c.setphone}" />
</aura:component>
4. Input Controller:
({
setphone : function(component, event, helper) {
var text = component.find("phone").get("v.value");
//alert(text);
console.log(text);
$A.get("e.c:PhoneNumberEvent").setParams({phone: text}).fire();
}
})
5. Phone Number Event :
<aura:event type="APPLICATION">
<aura:attribute name="phone" type="String"/>
</aura:event>