You need to sign in to do that
Don't have an account?
Shweta Hegde 5
Cannot read property 'setParam' of undefined
I am new to lightning components. Following is my code. When I run my code I am getting the Error
"Action failed: c:SearchBar$controller$SearchKeyChange [Cannot read property 'setParam' of undefined] Failing descriptor: {c:SearchBar$controller$SearchKeyChange}"
Please help me to resolve the issue.
// This is my Application
<aura:application>
<div >
<a href="#" >Lightning Contacts</a>
</div>
<div >
<c:SearchBar/>
<c:ContactList/>
</div>
</aura:application>
//This is component
<aura:component >
<input type="text" placeholder="Search" onkeyup="{!c.SearchKeyChange}"/>
</aura:component>
//This is controller
({
SearchKeyChange : function(component,event, helper) {
debugger;
var myEvent=$A.get("e.c:SearcKeyChange");
debugger;
myEvent.setParam({"SearchKey":event.target.value});
debugger;
myEvent.fire();
}
})
//This is Event
<aura:event type="APPLICATION" description="Event template" >
<aura:attribute name="SearchKey" type="String"/>
</aura:event>
//This is another component
<aura:component controller="ContactController" >
<aura:attribute name="contacts" type="Contact[]"/>
<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
<aura:handler event="c:SearchKeyChange" action="{!c.SearchKeyChange}"/>
<ul>
<aura:iteration items="{!v.contacts}" var="contact">
<li>
<a href="{!'#contact/'+contact.Id}">
<p>{!contact.Name}</p>
<p>{!contact.Phone}</p>
</a>
</li>
</aura:iteration>
</ul>
</aura:component>
"Action failed: c:SearchBar$controller$SearchKeyChange [Cannot read property 'setParam' of undefined] Failing descriptor: {c:SearchBar$controller$SearchKeyChange}"
Please help me to resolve the issue.
// This is my Application
<aura:application>
<div >
<a href="#" >Lightning Contacts</a>
</div>
<div >
<c:SearchBar/>
<c:ContactList/>
</div>
</aura:application>
//This is component
<aura:component >
<input type="text" placeholder="Search" onkeyup="{!c.SearchKeyChange}"/>
</aura:component>
//This is controller
({
SearchKeyChange : function(component,event, helper) {
debugger;
var myEvent=$A.get("e.c:SearcKeyChange");
debugger;
myEvent.setParam({"SearchKey":event.target.value});
debugger;
myEvent.fire();
}
})
//This is Event
<aura:event type="APPLICATION" description="Event template" >
<aura:attribute name="SearchKey" type="String"/>
</aura:event>
//This is another component
<aura:component controller="ContactController" >
<aura:attribute name="contacts" type="Contact[]"/>
<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
<aura:handler event="c:SearchKeyChange" action="{!c.SearchKeyChange}"/>
<ul>
<aura:iteration items="{!v.contacts}" var="contact">
<li>
<a href="{!'#contact/'+contact.Id}">
<p>{!contact.Name}</p>
<p>{!contact.Phone}</p>
</a>
</li>
</aura:iteration>
</ul>
</aura:component>
<aura:registerEvent name="searchKeyEvt" type="c:SearchKeyChange"/>
missing event register statement