0

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); 
   }

})
1
  • 1
    Use action.setParams({"str" : sear}); Nov 27, 2018 at 13:02

1 Answer 1

4

You should actually need to use JSON syntax to pass params using action.setParams() method.

So in your case you need to pass it either like this:

action.setParams({str:sear});

Or like this:

action.setParams({"str":sear});

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .