You need to sign in to do that
Don't have an account?

Separate input and output components
I'm trying to build two separate components for a home page. The first one will be a Rich Text input for a few assigned users to be able to enter a message on. The second component will be the output. I've built code to do this but I'm getting an error on function post:
Uncaught Action failed: c:parenttest$controller$post [Cannot read property 'setParams' of undefined]
I'm new to coding so I'm probably missing something simple.
Parent component:
<aura:component implements="flexipage:availableForAllPageTypes" access="global" >
<aura:registerEvent name="loadMyEvent" type="c:resultTest"/>
<aura:attribute name="myVal" type="String" />
<lightning:inputRichText value="{!v.myVal}" placeholder="Type message."/>
<lightning:button label="Save" onclick="{!c.post}"/>
</aura:component>
Parent JS:
({
post : function(component, event, helper) {
var evt = $A.get("e.c:restultTest");
evt.setParams({ "Pass_Result": component.get("v.myVal")});
evt.fire();
}
})
Child component:
<aura:component implements="flexipage:availableForAllPageTypes" access="global" >
<aura:attribute name="Get_Result" type="String" />
<aura:handler event="c:resultTest" action="{!c.getValueFromApplicationEvent}"/>
The result is {!v.Get_Result}
</aura:component>
Child JS:
({
getValueFromApplicationEvent : function(cmp, event) {
var ShowResultValue = event.getParam("Show_Result");
// set the handler attributes based on event data
cmp.set("v.Get_Result", ShowResultValue);
}
})
Event:
<aura:event type="APPLICATION">
<aura:attribute name="Pass_Result" type="String"/>
</aura:event>
Uncaught Action failed: c:parenttest$controller$post [Cannot read property 'setParams' of undefined]
I'm new to coding so I'm probably missing something simple.
Parent component:
<aura:component implements="flexipage:availableForAllPageTypes" access="global" >
<aura:registerEvent name="loadMyEvent" type="c:resultTest"/>
<aura:attribute name="myVal" type="String" />
<lightning:inputRichText value="{!v.myVal}" placeholder="Type message."/>
<lightning:button label="Save" onclick="{!c.post}"/>
</aura:component>
Parent JS:
({
post : function(component, event, helper) {
var evt = $A.get("e.c:restultTest");
evt.setParams({ "Pass_Result": component.get("v.myVal")});
evt.fire();
}
})
Child component:
<aura:component implements="flexipage:availableForAllPageTypes" access="global" >
<aura:attribute name="Get_Result" type="String" />
<aura:handler event="c:resultTest" action="{!c.getValueFromApplicationEvent}"/>
The result is {!v.Get_Result}
</aura:component>
Child JS:
({
getValueFromApplicationEvent : function(cmp, event) {
var ShowResultValue = event.getParam("Show_Result");
// set the handler attributes based on event data
cmp.set("v.Get_Result", ShowResultValue);
}
})
Event:
<aura:event type="APPLICATION">
<aura:attribute name="Pass_Result" type="String"/>
</aura:event>
var evt = $A.get("e.c:restultTest"); it should be c:resultTest
if it helps please mark as correct, it may help others
I'm still getting the same error for setparams.
Use the name, not the type of the event you registered.
if it solves your issue mark as correct so this can help others.
good luck