0

This is my subscribe method:

 public invokeUnlockModal() {
   let resetPassword = { userName: this.user?.userName};    //i need to send this to _confirmToUnlock method
      this.infoModal.componentInstance.emitUserOp
                     .subscribe({ next: this._confirmToUnlock });
  }

It calls this method

    private _confirmToUnlock = async (response: { opStatus: string }) => {
        
      if (response.opStatus.toLowerCase() === 'confirmed') {
          
//  let resultObs= this.dataService.unlockUser(resetPassword);
  //let result= await resultObs.toPromise();
         }
      }

My question how to send resetPassword data to _confirmToUnlock method in typesecript/rxjs.

Please le me know

Glen
  • 321
  • 4
  • 15
  • I don't get it, why do you want to work with promises alongside observables? could you provide more context please? like a "reproducible" example? – Dario Piotrowicz Jun 15 '21 at 10:30
  • the method is working fine without parameter. but i need to send parameter to private method? how to send that? – Glen Jun 15 '21 at 10:33
  • ahhhh ok I see, I didn't read the question properly :P, anyways @Michael D's answer is ok for you :) – Dario Piotrowicz Jun 15 '21 at 11:22

1 Answers1

1

I'm unfamiliar with this Modal definition, but if it's a simple callback, you could use an arrow function to send arguments.

Try the following

public invokeUnlockModal() {
  let resetPassword = { userName: this.user?.userName };
    this.infoModal.componentInstance.emitUserOp.subscribe({ 
      next: (response: any) => this._confirmToUnlock(response, resetPassword)
    });
}

private _confirmToUnlock = async (response: { opStatus: string }, resetPassword: any) => {
  // use `resetPassword`
  if (response.opStatus.toLowerCase() === 'confirmed') {
  }
}

I'd also suggest to avoid mixing Promises and Observables. It'd make the app hard to maintain. Either convert all to Observables or vice-versa.

ruth
  • 29,535
  • 4
  • 30
  • 57
  • Thanks you @michael for suggestion...actaully i use asnc method..for ng bootrap modal i have used observable..this.infoModal.componentInstance.emitUserOp.subscribe({ next: (response: any) => this._confirmToReset(response, resetPassword) }); – Glen Jun 15 '21 at 10:44
  • Is it possible to convert to async syntax..? – Glen Jun 15 '21 at 10:45
  • 1
    @Glen: There are ways to convert Observables to Promises (https://stackoverflow.com/a/36777294/6513921) and vice-versa (https://stackoverflow.com/a/50799101/6513921). – ruth Jun 15 '21 at 10:47