我很难理解RxJ。5和6之间的突破性变化对我来说很难理解。
我有以下代码和以下问题。
Observable
我检查了changelog和修复破坏更改的建议,但我无法确定我需要做什么。据我所知,我的代码是旧的,没有使用管道运算符,但这就是我能弄明白的全部。
let polling = Observable.interval(2000)
.switchMap(() => this.http.get(this.videoStatusURL + this.taskID))
.subscribe(
(data) => {
if (data["state"] === "SUCCESS") {
//get final video here
console.log("polling succeeded");
this.downloadFinalVideo();
polling.unsubscribe();
}
},
error => this.handleError(error));
发布于 2018-05-30 08:49:53
请参阅关于pipe syntax in the migration doc的小节,运算符必须通过调用.pipe()
来调用,因此您需要执行如下操作
import { interval } from 'rxjs';
import { switchMap } from 'rxjs/operators';
let polling = interval(2000)
.pipe(switchMap(() => this.http.get(this.videoStatusURL + this.taskID)))
.subscribe(
(data) => {
if (data["state"] === "SUCCESS") {
//get final video here
console.log("polling succeeded");
this.downloadFinalVideo();
polling.unsubscribe();
}
},
error => this.handleError(error));
或者,您也可以安装rxjs-compat
,但是这只是一个兼容层,您应该真正使用管道语法。
https://stackoverflow.com/questions/50592218
复制相似问题