我是 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/