相关疑难解决方法(0)

为什么我们需要使用flatMap?

我开始使用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)

如果有人可以直观地解释发生了什么,那将非常有帮助.

javascript rxjs

82
推荐指数
10
解决办法
9万
查看次数

如何在rxjs中执行链序列

我想要的是:

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)

javascript http rxjs typescript angular

38
推荐指数
3
解决办法
7万
查看次数

标签 统计

javascript ×2

rxjs ×2

angular ×1

http ×1

typescript ×1