Vorrei a qualcosa di simile:Come fare la sequenza della catena in rxjs
this._myService.doSomething().subscribe(result => {
doSomething()
});
.then(() => dosthelse())
.then(() => dosanotherthing())
Così Vorrei catena .then come nella promessa. Come lo farei in 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(observer => {
window.location.href = myService.LOGIN_URL;
observer.next();
});
}
Eventuali duplicati di [Chaining RxJs osservabili in angolare 2] (http://stackoverflow.com/questions/37180607/chaining-rxjs-observables-in -angular-2) – rinukkusu
fai attenzione ai tuoi tipi !! '.subscribe' restituisce un' Disposable' non un 'Observable' – user3743222