嗨,我是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
};
});
});
}
答案 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);
}