0

I am having two client-side controller methods, How to pass the response of the first wire method as a parameter to the second wire method. The second wire method is dependent on the first methods returned data.

@wire(method2, { oinputmap: "$inputMap", intname: "$interName" })
  wiredresponse({ error, data }) {
    //({ oinputmap: this.inputMap,intname: this.interName })
    if (data) {
      var responseObj = JSON.parse(data);
      console.log("result activate card" + responseObj);
      if (responseObj.Result.Code === 0) {
        this.description = "Card Activated." + responseObj.Result.Description;
        //TODO: Update XPAC in card
      } else {
        this.description = responseObj.Result.Description;
      }
      console.log("result" + responseObj.Result.Description);
    } else if (error) {
      console.log("buildandcallinterface:Exception in fetching card number");
    }
  } 
1

1 Answer 1

1

Create @api or @track params responseFromFirstMethod that will store your result from method1 and apparently update the value of the parameter, pass that parameter into second method2 wire method.

 @track = responseFromFirstMethod

 @wire(method1, { oinputmap: "$inputMap", intname: "$interName" })
 wiredresponse({ error, data }) {
  if(data){ 
     this.responseFromFirstMethod = data
 }

 @wire(method2, { param : "$responseFromFirstMethod" })
 wiredresponse({ error, data }) {
  if(data){
    //get the data
  }
 }
1
  • The comment on this question had a link to a better answer that explains what should be done and why.
    – Phil W
    Mar 13, 2020 at 13:22

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