Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/31.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/284.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 调用返回可观察对象而不是实际对象_Javascript_Angular_Typescript_Observable_Subscription - Fatal编程技术网

Javascript 调用返回可观察对象而不是实际对象

Javascript 调用返回可观察对象而不是实际对象,javascript,angular,typescript,observable,subscription,Javascript,Angular,Typescript,Observable,Subscription,我对this.dashboardFacade.getCurrentUseruid.thenuser=>console.loguser的调用;不断返回一个可观察的对象而不是实际的数据对象-有人知道如何修复它吗 仪表板组件 仪表板正面 引发以下错误: promise中未捕获的:TypeError:this.dashboardFacade.getCurrentUser…subscribe不是函数TypeError:this.dashboardFacade.getCurrentUser…subscrib

我对this.dashboardFacade.getCurrentUseruid.thenuser=>console.loguser的调用;不断返回一个可观察的对象而不是实际的数据对象-有人知道如何修复它吗

仪表板组件

仪表板正面

引发以下错误:


promise中未捕获的:TypeError:this.dashboardFacade.getCurrentUser…subscribe不是函数TypeError:this.dashboardFacade.getCurrentUser…subscribe不是仪表板组件中的函数。它发生在我承诺返回一个承诺时,中间承诺有点看不见,你会收到最后一个承诺链的结果

您的方法getUser返回一个承诺,但这个承诺实际上不返回另一个承诺,而是一个可观察的承诺,在这种情况下,不涉及链承诺,您将收到一个可观察的承诺。如果您不需要观察,您可以做些什么来转换您的方法以实际返回承诺:

getUseruid:string:Promise{ 返回火基 作者 .currentUser.getIdToken .thentoken:string=>{ debug`Token generated:${Token}`; 返回此.httpClient .get`${environment.apiBasePath}/users`{ 标头:{授权:`Bearer${token}`, }.toPromise;console.loguser; }; } };
当您进行HTTP调用时,它会返回一个可观察的值。您可以尝试使用可观察而不是承诺。看看这是否有效,让我知道..所以你们可以把那个可观察的转换成承诺,或者简单地用作为可观察的结束语句。告诉我们这是退货类型。这就是问题所在。我认为问题出在getUseruid:string中,它返回一个承诺,而不是可观察的
this.dashboardFacade.getCurrentUserUid().then((uid) => {
  if (uid) {
    this.dashboardFacade.getCurrentUser(uid).then((user) => console.log(user));
  }
});
  getCurrentUser(uid: string): Promise<unknown> {
    return this.userService.getUser(uid);
  }
  getUser(uid: string): Promise<unknown> {
    return firebase
      .auth()
      .currentUser.getIdToken()
      .then((token: string) => {
        this.logger.debug(`Token generated: ${token}`);
        return this.httpClient
          .get(`${environment.apiBasePath}/users`, {
            headers: { authorization: `Bearer ${token}` },
          })
      });
  }
this.dashboardFacade.getCurrentUserUid().then(uid => {
  if(uid) {
    this.dashboardFacade.getCurrentUser(uid).subscribe(
     (user) => console.log(user)
    )
  }
});
this.dashboardFacade.getCurrentUserUid().then(uid => {
  if(uid) {
    this.dashboardFacade.getCurrentUser(uid).subscribe(
     (user) => console.log(user)
    )
  }
});