我开始使用RxJS,我不明白为什么在这个例子中我们需要使用像flatMap或的函数concatAll; 这里的数组数组在哪里?
var requestStream = Rx.Observable.just('https://api.github.com/users');
var responseMetastream = requestStream
.flatMap(function(requestUrl) {
return Rx.Observable.fromPromise(jQuery.getJSON(requestUrl));
});
responseMetastream.subscribe(url => {console.log(url)})
Run Code Online (Sandbox Code Playgroud)
如果有人可以直观地解释发生了什么,那将非常有帮助.
我想要的是:
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)