【问题标题】:error TS2339: Property 'do' does not exist on type 'Observable<错误 TS2339:属性 'do' 不存在于类型 'Observable<
【发布时间】:2018-05-06 00:27:42
【问题描述】:

尝试从 Angular 5.2 升级到 Angular 6.0.0,我们遇到以下错误:

error TS2339: Property 'do' does not exist on type 'Observable<

有什么想法吗?

我们使用的代码是

return this.httpClient.post<x>(`${environment.apiUrl}auth/x/`,
  this.abcd,
  httpOptions)
  .do(x1 => this.subject.next(x1))

【问题讨论】:

    标签: angular angular-upgrade


    【解决方案1】:

    链运算符不久前被弃用,现在它们已被删除。使用管道运算符,在这种情况下 tap 替换 do

    import { tap } from 'rxjs/operators';
    
    return this.httpClient.post(ˋ${environment.apiUrl}auth/x/ˋ, this.abcd, httpOptions)
    .pipe(
        tap(x1 => this.subject.next(x1))
    );
    

    【讨论】:

      【解决方案2】:
      import{ scan,tap,take} from 'rxjs/operators'
      

      do 运算符现在替换为 tap 运算符和 我们只能在 管道 内使用所有这些 rxjs 运算符。

      【讨论】:

      • 这个答案在接受的答案上有何改进?
      猜你喜欢
      • 2018-10-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-29
      • 2018-11-03
      • 2019-03-02
      • 1970-01-01
      • 2018-12-10
      相关资源
      最近更新 更多