我有以下代碼
let arrApi = [];
arrApi.push(this.securityService.deleteBusinessDataRule('1000').pipe(catchError(error => of({error: true}))))
forkJoin([...arrApi]).subscribe((forking: any) => {
console.log('forking', forking);
});
所以我正在通過t動態構建api請求arrApi。該方法(this.securityService.deleteBusinessDataRule('1000')
回傳可觀察的。它是洗掉請求,它得到 204 作為狀態碼。如果里面有一些錯誤,我會發現錯誤,所以forking[0]
我會得到error: true一個值,因為我在 observable 中發現了錯誤,我會使用它。
我不知道成功后如何捕捉回應?因此,當 observable 通過時,我想發出像 {error: false} 這樣的值,因為在我點擊洗掉 API 之后,這個洗掉請求不會在回應中回傳任何內容,并且我一直在forking[0].
所以每次當 observable 被競爭時,我都需要得到 {error: false}
uj5u.com熱心網友回復:
您可以只使用maprxjs 中的運算子:
arrApi.push(
this.securityService.deleteBusinessDataRule('1000')
.pipe(
map(()=>({error: false})),
catchError(error => of({error: true}))
)
)
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/510212.html
標籤:有角度的rxjs
