I have to perform two different DB transactions on a single (click) event.
First Call : Save Data to DB.
Second Call : Get the first call's saved data from DB
These calls are separated in two different components and deal with one common DB Table.
My approach is below :
First Component TS :
ngOnDestroy(){ this.saveData(); }
Second Component TS :
ngOnInit(){ this.getSavedData(); }
Service call for First Method to Execute :
saveData(obj) {
return this.http.post(environment.appUrl + 'saveDataApi', obj).toPromise()
.then(res => <any>res); }
Both these methods are getting triggered sequentially as coded. But my issue is that this.getSavedData(); completes its DB transaction earlier before Save method's DB transaction is completed & response is returned.
I need that the service call for 'Save' method should wait for DB response and then proceed to 'Get' method in other component.
In short : this.getSavedData(); should not be executed until and unless this.SaveData(); completes its entire execution returning a response.
What am I missing?