首页 > 解决方案 > 如何返回嵌套订阅?

问题描述

我有以下嵌套订阅,我需要返回内部订阅。我该怎么做呢?

public updateProfiles(){
    this.afAuth.idToken.subscribe(idToken=>{
      return this.httpClient.post<any>('https:example.com/getData',{
        "token": idToken,
        "np":"hzlNpV1239nOKRTcsVdPG",
        "cp":"M6nKYrSjsnA9v34vfB8oD"
      });
    })

  }

在调用模块中,我想 this.authService.updateProfiles.subscribe(()=>{do something});

标签: angularobservable

解决方案


您应该使其可管道化。

updateProfiles() {
  this.afAuth.idToken.pipe(
    switchMap(idToken => this.httpClient.post(your stuff))
  ).subscribe(result => console.log(result))
}

推荐阅读