I'm using subscribe which is asynchronous and so the counter variable is being returned before getting updated. Is there an alternative to subscribe that will allow me to only return the counter variable once its updated with the value gotten from the backend?
makeOffer(product: string, offer: number): number {
let formData = new FormData();
formData.append('name', product);
formData.append('offer', offer.toString());
let counter = 1
this.http.post('http://localhost/Project/PHP/negotiation.php', formData)
.subscribe((data) => {
counter = data['counter']
}, (error) => {
console.log('Error! ', error)
});
return counter;
}