【问题标题】:How to use delay with HTTPClient Rxjs 6.3.0如何在 HTTPClient Rxjs 6.3.0 中使用延迟
【发布时间】:2019-04-04 19:31:17
【问题描述】:

使用 HTTPClient 对象的延迟给我如下错误:

无法调用类型缺少调用签名的表达式。类型“号码”没有兼容的调用签名。

TS:

import { delay } from 'rxjs/operators';

this.http.get(url,{params:search})
          .pipe(
              delay(1000),
              map(res => res)
          , catchError((error: any) => {
              return Observable.throw(error)
        }));

【问题讨论】:

    标签: angular typescript angular-httpclient rxjs6


    【解决方案1】:

    您不能延迟 HTTP 响应,但可以延迟返回值。这是正确的代码

    this.http.get(url,{params:search})
              .pipe(
                  map(res => res),
                  delay(1000), 
                  catchError((error: any) => {
                     return Observable.throw(error)
                  }
               ));
    

    【讨论】:

    • 你收到 HTTP 响应了吗?
    • 它的编译时错误。另外,我的想法是延迟请求,但正如你建议的延迟响应后不符合这个目的。
    • 您不能延迟 HTTP 请求。它很简单。使用 res:any
    • 不起作用。可能与 tsconfig 相关
    猜你喜欢
    • 2019-10-08
    • 1970-01-01
    • 2018-10-17
    • 2018-11-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多