Angular 7 get方法将其余API URL附加到应用程序URL中

时间:2019-02-19 11:35:56

标签: rest angular7 angular-httpclient

嗨,我是Angular的新手,我试图使用Angular方法进行get调用(localhost:8080/optq/api/test/roles),但它是将我的主机应用程序URL附加到REST API URL上。 我缺少什么部分?

http://localhost:4200/localhost:8080/optq/api/test/roles 404 (Not Found)

代码

getRoles(){
    this.http.get(this.rolesUrl)
    .subscribe((payload: Payload<Role>) => {
        this.roleList = payload.result.map((response: Role) => {
          return <Role>{
            id: response.id,
            name: response.name
          };
        });
      });
}

1 个答案:

答案 0 :(得分:0)

尝试使用以下get方法

get(url: string): Promise<any> {
            return this.http
                .get(url, { headers: this.headers })
                .toPromise()
                .then(res => {
                    return res.json() as any;
                })
                .catch(this.handleError);
        }