I am making the http connection to my system in angular7. But, it is giving error in the module. This message appears when I created the get request:
Type 'Promise<any>' is missing the following properties from type 'User': id, user, email
Module:
export class User {
id: number
user: string
email: string
}
Request:
users: User;
this.userService.getUsers().subscribe(
response => {
if (!response) {
console.log(Error)
} else {
this.users = response
}
})
Http Get:
getUsers() {
return this.service.get(this.endpoint)
.map((response) => {
return response;
});
}
service:
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();
});
}
path = endpoint
I found the problem, it was only to change the request of:
users: User;
this.userService.getUsers().subscribe(
response => {
if (!response) {
console.log(Error)
} else {
this.users = response
}
})
for:
this.userService.getUsers().subscribe(
response => {
if (!response) {
console.log(Error)
} else {
console.log(response)
let users : User[] = response
}
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With