首页 > 解决方案 > 在 rxjs 中调用下一个方法另一个私有方法

问题描述

这是我的订阅方法:

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

它调用这个方法

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

我的问题是如何将 resetPassword 数据发送到 typesecript/rxjs 中的 _confirmToUnlock 方法。

请让我知道

标签: angulartypescriptrxjs

解决方案


我不熟悉这个 Modal 定义,但如果它是一个简单的回调,你可以使用箭头函数来发送参数。

尝试以下

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') {
  }
}

我还建议避免混合 Promises 和 Observables。这会使应用程序难以维护。将所有转换为 Observables,反之亦然。


推荐阅读