我想要的是:
this._myService.doSomething().subscribe(result => {
doSomething()
});
.then( () => dosthelse() )
.then( () => dosanotherthing() )
Run Code Online (Sandbox Code Playgroud)
所以我想链接.然后像承诺一样.我如何在Rxjs中做到这一点?
this._myService.getLoginScreen().subscribe( result => {
window.location.href = MyService.LOGIN_URL;
/// I would like to wait for the site to load and alert something from the url, when I do it here it alerts the old one
});
.then (alert(anotherService.partOfTheUrl())
getLoginScreen() {
return this.http.get(myService.LOGIN_URL)
.flatMap(result => this.changeBrowserUrl())
.subscribe( result => //i want to do sth when the page is loaded//);
}
changeBrowserUrl(): Observable<any> {
return Observable.create( …Run Code Online (Sandbox Code Playgroud) 假设我动态创建一个可观察数组:
let obsArray = dataArray.map((data) => observableFunc(data))
Run Code Online (Sandbox Code Playgroud)
我想按顺序执行这些observable中的每一个,只有在obsArray [n]完成后才执行obsArray [n + 1].下一个可观察的执行不依赖于先前可观察的结果.
在数组中的每个observable完成后,我想从处理此可观察数组的函数返回.
本质上,我想找到一个像forkJoin这样的方法来确保顺序执行.
我想将多个请求链接到从数组中获取的网址。在下一个链之前,我要等待上一个链完成。先前的失败与否无关紧要。我试图用forkJoin做到这一点,但我知道,如果请求之一失败,它将返回错误。
this.dataServers.forEach(dataServer => {
observableBatch.push(this.getFoodsByQuery(dataServer.url, query));
});
return Observable.forkJoin(observableBatch).subscribe(data => {
this.searchingServer.next(null);
observer.complete();
});
Run Code Online (Sandbox Code Playgroud)
我不知道如何用flatMap做到这一点。