【发布时间】:2021-03-15 17:00:50
【问题描述】:
我保存了个人资料,一旦请求成功,我会再次请求创建付款。现在的代码是这样的
this.profileService.saveProfile(dataProfile).pipe(
catchError(e => of(null))
).subscribe(res => {
if (res) { // if user saved profile data
const data = {
params: {
user: {
surname: this.formInfo.get('surname').value,
name: this.formInfo.get('name').value,
father_name: this.formInfo.get('father_name').value,
iin: this.formInfo.get('iin').value,
},
tariff: obj ? {
months: obj.Months,
amount: obj.Amount,
amountByMonth: obj.AmountByMonth
} : null,
}
this.buyService.create(data).pipe( ...
}
让这段代码变得更好的最好方法是什么?我在RXjs 中阅读了有关concatMap 运算符的信息,但这与Observables 数组有关,如果用户保存自己的数据,这里我只有一个响应。
另外,我应该如何在此处为每个请求单独处理 loading 变量?
【问题讨论】: