Zac*_*scs 7 javascript rxjs angular
我有一个角度应用程序,它向Http服务发出请求,并在另一个Http服务上调用switchMap.由于某种原因,switchMap中的请求仅在第一次调用父调用时运行.否则父请求将触发,而switchMap不会触发,这里是代码:
this._receivableService.newTenantDebitCredit(tenantCredit)
.take(1)
.switchMap(result =>
// Refresh the lease receivables before giving result
this._receivableService.getAll({
refresh: true,
where: { leaseId: this.leaseId }
}).take(1).map(() => result)
)
.subscribe(
...
)
Run Code Online (Sandbox Code Playgroud)
每次在上面调用newTenantDebitCredit方法时,如何在switch map中运行getAll请求?
编辑:这是调用的函数的全部内容click.当我第一次单击按钮时,给定单元执行两种方法.如果我尝试已经调用该方法的单元(没有刷新),则只执行第一个方法.我意识到很多这可能并不清楚,这是一个相当大的项目.
public submitTenantCredit() {
this.isLoading = true;
let tenantCredit: NewTenantDebitCreditData;
let receivableDefinitions: ReceivableDefinition[] = [];
// construct receivable defintions for NewTenantDebitData model
receivableDefinitions = this._constructReceivableDefinitions();
// construct data we will be POSTing to server.
tenantCredit = new NewTenantDebitCreditData({
siteId: this._apiConfig.siteId,
leaseId: this.leaseId,
isCredit: true,
receivables: receivableDefinitions,
reason: this.actionReason
});
// make service call and handle response
this._receivableService.newTenantDebitCredit(tenantCredit)
.take(1)
.switchMap(result =>
// Refresh the lease receivables before giving result
this._receivableService.getAll({
refresh: true,
where: { leaseId: this.leaseId }
}).take(1).map(() => result)
)
.take(1)
.subscribe(
(receivables) => {
this.closeReasonModal();
let refreshLeaseId = this.leaseId;
this.leaseId = refreshLeaseId;
this.isLoading = false;
this.refreshBool = !this.refreshBool;
this._debitCreditService.refreshUnitInfo();
this._notifications.success(`The tenant credit for ${this.customerName} - Unit ${this.unitNumber} was submitted successfully`);
},
(error) => {
console.error(error);
this.isLoading = false;
}
)
}
Run Code Online (Sandbox Code Playgroud)
如果有帮助newTenantDebitCredit()是HTTP POST请求并且getAll()是GET请求.
不是真正的答案,但我确实解决了我的问题。它几乎肯定对任何人都没有用,但这是 receivableService 中的一个问题,它没有正确地检查boolean:refresh并且在第一次之后从缓存中提取值。
| 归档时间: |
|
| 查看次数: |
1588 次 |
| 最近记录: |