This page has an error. You might just need to refresh it. Action failed: c:SComponent$controller$arResult [str is not defined] Failing descriptor: {c:SComponent$controller$arResult}
when click on the button whatever text i have entered is showing in alert box which is correct but after alert i am setting parameter from setParams it's throwing error str is not defined.
i have use this in this way :--> action.setParams({str,sear});
and this way -->action.setParams({"str",sear}); and everytime i am getting same error which is mentioned above.
Apex Controller Code is below
public class SearchController {
@AuraEnabled
public static List<Contact> archCon(String str){
List<contact> conList = new List<contact>();
if(Str != null){
conList = [SELECT id FirstName, LastName, phone FROM CONTACT WHERE FirstName =: str];
}
return conList;
}
}
Component code below
<lightning:input type="text" aura:id="input1" label="Enter a text" />
<lightning:button label="Search Record" title="Search" onclick="{!c.arResult }"/>
Component controller code is below
({
arResult : function(component, event, helper) {
var sear = component.find("input1").get("v.value");
alert(sear);
var action = component.get("c.archCon");
**action.setParams({str,sear});**
action.setCallback(this, function(response){
if(response.getState()==="SUCCESS" && component.isValid()){
alert("From server: " + response.getReturnValue());
}
});
$A.enqueueAction(action);
}
})