angular - rxjs 管道 : Argument of type Observable not assignable to parameter

标签 angular rxjs6

我是 rxjs 和管道的新手 - 并费尽心思试图理解为什么我会收到此 typescript 错误:“Observable 类型的参数无法分配给参数 OperatorFunction”。有人可以向我解释一下吗?

目的是询问“Hello”,但在数据通过管道传输时将数据替换为“Bye”。

  ngOnInit() {
    this.getHello()
      .pipe(this.getBye())
      .subscribe(data => console.log(data))
  }
  getHello() {
    return of("Hello")
  }
  getBye() {
    return of ("Bye")
  }
}

最佳答案

使用映射作为可管道操作符:

this.getHello()
  .pipe(map((data) => { return this.getBye() }))
  .subscribe(data => {
    console.log(data);
  });
getHello() {
  return of("Hello");
}
getBye() {
  return of("Bye");
}

详细检查可管道运算符的链接:https://angular.io/guide/rx-library https://blog.hackages.io/rxjs-5-5-piping-all-the-things-9d469d1b3f44

关于angular - rxjs 管道 : Argument of type Observable not assignable to parameter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52413693/

相关文章:

javascript - 如何以正确的方式表示两个日期之间的日期数组列表?

Angular, Central (Redux )'Store' vs Singleton Service, aka "what happened to separation of concerns"?

angular - RxJs 6 : Get ConnectableObservable from Observable

angular - 从 HttpInterceptor 中的 catchError 返回可观察到的捕获错误会导致错误循环

angular - 如何更改 Angular 2 Material 2 中的 md-autocomplete 宽度?

angular - 如何在 Angular 应用程序中使用 powerbi-client 依赖项,而不破坏 Jest 测试?

rxjs - 如何通过 catchError() 正确传播错误?

javascript - 当我们想要订阅可观察数组时如何进行错误处理

angular - 如何从 Angular 7 中的 Observable 返回对象

Angular 2 组件少路由,在匹配特定 URL 时执行任何逻辑并进一步重定向