I am currently working on creating a function that returns a Promise in the code snippet below (someprovider.ts)
postToPaymentApi(url:string, data:string, options:RequestOptions, order:Order):Promise<any>{
let result = this.http.post(url, data, options).map(res => res.json())
.subscribe(data => {
// all my logic here!
});
}, error => {
console.log(error)
})
return new Promise((resolve)=>{
resolve(result)
})
}
The issue arises when I call this function and do not receive the expected data. This is because the post request takes some time to complete and the promise resolves before that.
this.postToPaymentApi(url, data, options, order).then(data => {
console.log(data);
})
Can anyone help me identify what mistake I am making?