【发布时间】:2017-01-25 08:50:17
【问题描述】:
我想将多个 http 请求分叉到一个 observable 中,按间隔调用它并在所有订阅者之间共享相同的数据。
到目前为止,我的代码如下所示:
import {Observable} from "rxjs/Rx";
let obs = Observable
.interval(10000)
.publish()
.connect()
.forkJoin(
this.http.get(API_URL + "x", {headers: this.headers})
.map(response => response.json()),
this.http.get(API_URL + "y", {headers: this.headers})
.map(response => response.json())
)
.map(res => {
// do some stuff
return res;
});
错误:
Typescript Error
Property 'forkJoin' does not exist on type 'Subscription'.
我读过:
https://blog.thoughtram.io/angular/2016/06/16/cold-vs-hot-observables.html
Multiple $http requests in Ionic2
谢谢!
【问题讨论】:
-
你试过没有
publish()和connect()吗? -
导致此错误:“Observable
”类型上不存在属性“forkJoin”。 -
至少你有一个 Observable 而不是 Subscription。或许你会在stackoverflow.com/questions/38443798/…找到答案
-
我尝试了该链接中给出的所有提示,但没有任何帮助。我尝试更新到 rxjs 5.0.3 但结果相同。恢复到 5.0.0-beta.12
-
forkJoin是一个静态的 Observable 方法...你应该用Rx.Observable.forkJoin(...)调用它
标签: http ionic2 observable intervals