可观察的是分别返回字符串的每个字母

时间:2019-01-29 01:36:59

标签: angular typescript firebase rxjs observable

我有一些代码可以将数据发送到Firebase,等待响应,然后将结果显示给用户:

...
const loading = () => <LoadingSpinner/>;

const Login = Loadable({
  loader: () => import('./login.container.ts'),
  loading
});
...

正在超时,但这不是我的问题。我的问题是,当它返回超时错误时,一次会发送一个字母-控制台显示:

R
e
q
(等等)

HTML(sendRequest (data): Observable<any> { // Send to Firebase const key = this.db.list("Requests").push(data).key return this.db.object(`Requests/${key}`).valueChanges().pipe( timeout(30000), skipWhile(request => !request["response"]), // wait for either response or timeout take(1) // stop once a response is received ) } sendOrderRequest(data): Observable<string> { return this.sendRequest(data).pipe( map(response => { // stuff that happens on success }), catchError(error => { if (error.name === "TimeoutError") { return "Request timed out." } else { return "An unknown error occurred." } }) ) } confirmSubmit () { this.sendOrderRequest(this.data).subscribe(result => { console.log(result) this.result = result } } )中的数据绑定仅在最后显示句点。怎么了?

1 个答案:

答案 0 :(得分:2)

catchError应该返回一个可观察值。

catchError(error => {
    if (error.name === "TimeoutError") {
        return of("Request timed out.")
    } else {
        return of("An unknown error occurred.")
    }
})