我正在尝试发出get请求,但不知怎的,我无法从后端记录承诺。有什么想法我做错了什么?
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');
}
});
}
答案 0 :(得分:3)
收到回复后,您需要解析Promise
,以便在解决后立即调用基础.then
函数。
<强>代码强>
makeLoginCall(_username: string, _password: string) {
let promise = new Promise((resolve, reject) => {
this.http.get('xxx').subscribe(data => {
resolve(data); //resolve promise here
});
});
return promise;
}