如何在Angular中将数据传递给订户

问题描述 投票:0回答:2

我有以下服务,订阅了“ 用户”。

 public getEmployees(): Observable<User> {
    const url = `${this.baseUrl}/employee`;
    return this.http.get<User>(url);
  }

我的问题是如何使用用户数据调用getEmployees。我正在尝试使用以下代码,但出现错误?

const _user: User = {
      userId: "30294
}

 this.userAccountService.getEmployees().subscribe((userprofile: _user) => {
      console.log(userprofile.firstName);
    });

错误:_user引用值,但在此处使用其类型

angular angular-services subscribe
2个回答
0
投票

_user更改为User


0
投票

您正在使用_user作为userprofile: _user中的类型

© www.soinside.com 2019 - 2024. All rights reserved.