I am trying to subscribe to an Observable and store it in a variable
this.waiverData = this.waiverService
.searchForWaiver(this.waiverTypeId, this.policyNumber, this.dateOfLoss)
.subscribe(data => {
this.waiverData = data;
This is working to a point but the call is stopping at
.subscribe(data => {
and jumping straight to the if statement without capturing data from the object. It then runs through the if statement and once checking all of the conditions, it jumps back to the subscription at
this.waiverData = data;
and then returns the complete object with all the data that I need and is accessible. This happens too late.. Here is the complete function:
standardWaiver: StandardWaiver = new StandardWaiver();
// standardWaiver: StandardWaiver;
// standardWaiver: any;
dateOfLoss: Date = null;
waiverData: any;
async searchForDuplicateAndCAP() {
// the search for duplicate function will call the search for waiver in cap function
if (this.waiverTypeId === 1)
{
this.waiverData = this.waiverService
.searchForWaiver(this.waiverTypeId, this.policyNumber, this.dateOfLoss)
.subscribe(data => {
this.waiverData = data;
}
);
if (this.waiverData.duplicateFound === true) {
// console.log(this.duplicateFound, + 'if duplicate found')
this.showIfWaiverExistsInXXXXX = true;
this.showIfWaiverDataNotFoundInXXXXX = false;
}
else if (stuff){
}
else {
}
Do you have any idea of how to make the call complete before the if statement or why it's not. Thank you in advance. This is an updated question