angular - 在 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 方法。
请让我知道
解决方案
我不熟悉这个 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,反之亦然。
推荐阅读
- multithreading - ZeroMQ:线程在 while(1) 循环中恰好在 2 小时后停止。为什么以及如何解决这个问题?
- c# - 从 SQL 中选择唯一行并排除某些行 Mvc c#
- java - Java 1.4 的全局异常处理程序
- c - 使用 void 指针发送浮点数组时出现问题
- sql - 有没有办法从合并语句中检索值?
- javascript - 在 React Js 中将数组迭代为表单元素的问题
- javascript - 使用 expo 创建新的反应原生应用程序的问题
- python - 关于 Python Web 自动化的菜鸟问题
- unit-testing - 在谷歌测试框架中使用不同的参数多次运行相同的测试
- python - 按列值对 Pandas 数据帧进行采样