Answer the question
In order to leave comments, you need to log in
How to use await to wait for server response?
Good afternoon!
Tricky question.
There is a post request written in Angular, it is processed by the method of one service:
postHTTP(url, info: any) {
var some: any;
this.http.post(url, info, httpOptions).subscribe(
data => {
some = data;
console.log("POST Request is successful ", some);
},
error => {
console.log("Error", error);
}
);
return some;
}
constructor(
private myHttp: myHTTPService
) { }
....
async pars2gisplease() {
console.log( await this.myHttp.postHTTP('/pars2gis', {email: this.parser2gis}) );
}
Answer the question
In order to leave comments, you need to log in
postHTTP(url, info) {
return new Promise((resolve, reject) => {
this.http.post(url, info, httpOptions).subscribe((data) => {
resolve(data);
console.log("POST Request is successful ", data);
}, (error) => {
reject(error);
console.log("Error", error);
});
});
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question