Reputation: 363
I'm trying to make a get request but somehow I can't log the promise from backend. Any ideas what am I doing wrong ?
makeLoginCall(_username: string, _password: string) {
let promise = new Promise((resolve, reject) => {
this.http.get('xxx').subscribe(data => {
});
});
return promise;
}
login() {
this.userService.makeLoginCall(this.formLogin.value.username, this.formLogin.value.password)
.then(response => {
console.log(response);
},
(response) => {
if (response.status < 500) {
console.warn('Login failed!');
} else {
console.error('Internal Server Error');
}
});
}
Upvotes: 0
Views: 135
Reputation: 136134
You need to resolve the Promise
when you receive a response, so that the underlying .then
function will get call as soon it gets resolved.
Code
makeLoginCall(_username: string, _password: string) {
let promise = new Promise((resolve, reject) => {
this.http.get('xxx').subscribe(data => {
resolve(data); //resolve promise here
});
});
return promise;
}
Upvotes: 3