我正在尝试订阅带间隔的Observable
return IntervalObservable.create(10000)
.startWith(0) // needs a value, but won't be used
.flatMap(() => this._http.get(eazyUrl)).map(res => res.text())
这是订阅代码
var answer = this.LogService.getAdminHiererchy()
var Fdata: any;
answer.subscribe((response) => {
Fdata = response;
localStorage.setItem("AdminHiererchy", response);
console.log(Fdata);
},
error => {
var err = error;
alert("error");
}
, () =>{this.readyFunc(Fdata);})
this.readyFunc永远不会消防。
如果我删除intreval代码工作正常
return this._http.get(eazyUrl)
.map(res => res.text());
最后也没有运气
answer.finally(() => this.readyFunc(Fdata)).subscribe((response) => {...
还尝试使用具有相同resualt的计时器
return Observable.timer(0, 10000)
.flatMapTo(this._http.get(eazyUrl)).map(res => res.text());;
为什么使用intreval
时回调不会触发答案 0 :(得分:0)
删除startWith(0)
,我怀疑它会在您订阅之前终止您的信息流。
其他选项(因为没有记录IntervalObservable并且难以在jsbin中调用):
Observable.timer(1000).flatMap(...)
Observable.of(0).delay(1000).flatMap(...)
在第一种方法的每一行之后添加.do(v => console.log(v))
:
return IntervalObservable.create(10000)
.do(v => console.log('stage 1: ', v)
.startWith(0) // needs a value, but won't be used
.do(v => console.log('stage 2: ', v)
.flatMap(() => this._http.get(eazyUrl)).map(res => res.text())
.do(v => console.log('stage 3: ', v)