我有一个包含combineLatest的返回语句,它调用内部的两个函数。我想为这些函数添加 if 和 else block ,但到目前为止我还没有这样做。
return combineLatest([
this.firstfunction();
this.secondfunction()
]).pipe(
map(_ => Success()),
catchError(error => {
return error
})
);
我想要 if().... this.firstfunction() 和另一个 if().. this.secondfunction().. 目前,当我在 mergeLatest 中添加 if block 时,它会给出错误。有什么建议吗?
最佳答案
这个怎么样:
const observables = [];
if(conditionForFirstFuction) {
observables.push(this.firstFunction());
}
if(conditionForSecondFunction) {
observables.push(this.secondFunction());
}
return combineLatest(observables).pipe(
map(_ => Success()),
catchError(error => {
return error
})
);
关于javascript - 在 Angular 中将 if 和 else 与 mergeLatest 一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60186124/