簡體   English   中英

Angular 7:如何增加角度請求的時間

[英]Angular 7: How to increase the time of an angular request

我需要增加角度應用程序的請求時間,因為使用緩慢的Internet連接會發生超時。

我嘗試了下面的代碼,但出現了錯誤。

this.http.post(url, body, { headers: headers })
            .timeout(100, this.handleTimeout)
            .map(response =>{
                return response;
            })
            .catch(this.handleErrors);

屬性“超時”在類型“可觀察”上不存在。ts(2339)

使用攔截器也不成功

@Injectable()
export class AngularInterceptor implements HttpInterceptor {
  intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
    return next.handle(req).timeout(5000);
}

屬性“超時”在類型“可觀察>”上不存在。ts(2339)

謝謝

使用Rxjs 6,您將必須使用.pipe ,然后使用.timeout這樣的運算符,因此您的實現應如下所示:

import { 
  timeout,
  map,
  catch
} from 'rxjs/operators';


this.http.post(url, body, { headers: headers })
            .pipe(
             timeout(100, this.handleTimeout),
             map(response =>{
                return response;
             }),
            catch(this.handleErrors);

適用於我的最終解決方案:

import { timeout} from 'rxjs/operators';

return this.http.get(`${url}`).pipe(
            timeout(1000)
        );

感謝所有人的幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM