首页 文章

rxjs运算符将进行http调用但会忽略数据并且不会返回observable

提问于
浏览
0

我想进行HTTP调用并将输出作为observable(这是简单的部分),然后立即进行另一个HTTP调用并忽略输出 .

我不能使用switchMap运算符,因为第二个HTTP调用不会返回有用的东西 . 它只是返回'完成!'并且第一次调用返回我需要的复杂JSON .

我所做的,它的工作原理是订阅内部http调用,我想知道是否有一个rxjs运算符,我可以使用:

this.dataStorageBaseService.createIdentity(identity)
  .do(() => this.authService.JustSimpleHTTPCall().first().subscribe()).subscribe();

是否有一个RxJS运算符,我可以使用而不是再次订阅“JustSimpleHTTPCall”? map会很好但我不需要JustSimpleHTTPCall返回的数据,它不能与我需要返回的“createIdentity”输出一起作为observable .

2 回答

  • 3

    你可以这样做:

    this.dataStorageBaseService.createIdentity(identity)
      .concatMap(result => this.authService.JustSimpleHTTPCall()
        .map(() => result) // ignore the second response and use the first one instead
      )
      .subscribe(...);
    
  • 1

    你只需要你的内部Observable来发出外部结果 - 这可以用concat来完成

    this.dataStorageBaseService.createIdentity(identity)
      .switchMap(result => this.authService.JustSimpleHTTPCall().concat(Observable.of(result)))
      .subscribe(...);
    

相关问题