【发布时间】:2019-05-11 07:04:16
【问题描述】:
我正在 angular7 中与我的系统建立 http 连接。但是,它在模块中给出错误。当我创建 get 请求时出现此消息:
Type 'Promise<any>' is missing the following properties from type 'User': id, user, email
模块:
export class User {
id: number
user: string
email: string
}
请求:
users: User;
this.userService.getUsers().subscribe(
response => {
if (!response) {
console.log(Error)
} else {
this.users = response
}
})
http 获取:
getUsers() {
return this.service.get(this.endpoint)
.map((response) => {
return response;
});
}
服务:
standardHeaders() {
const headers = new HttpHeaders();
headers.append('Content-Type', 'application/json');
if (this.authToken) {
headers.append('X-Authorization', this.authToken);
}
return { headers: headers };
}
get(path: string) {
return this.http.get(this.url + path, this.standardHeaders()).map((response: Response) => {
return response.json();
});
}
路径 = 端点
【问题讨论】:
-
那么
console.log(response)的输出是什么? -
我还没有执行请求,因为后端 api 没有 100% 完成。
标签: typescript http angular7