chciałbym aby coś takiego:Jak zrobić sekwencję łańcucha w rxjs
this._myService.doSomething().subscribe(result => {
doSomething()
});
.then(() => dosthelse())
.then(() => dosanotherthing())
więc chciałbym aby łańcuch .then jak w obietnicy. Jak to zrobić w RxJ?
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(observer => {
window.location.href = myService.LOGIN_URL;
observer.next();
});
}
Możliwy duplikat [łańcuchowym RxJs obserwable kątowej 2] (http://stackoverflow.com/questions/37180607/chaining-rxjs-observables-in -wymiarowy-2) – rinukkusu
zwróć uwagę na swoje typy !! '.subscribe' zwraca' Disposable' not an 'Observable' – user3743222